南京博物院自动化预约

代码

python 复制代码
import time

import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 创建Edge浏览器实例
driver = webdriver.Edge()


def sendMsg(param):
    # 构建消息内容
    message = {
        "msgtype": "text",
        "text": {
            "content": param
        }
    }

    # 替换为您的企业微信Webhook地址
    webhook_url = "**************"

    # 发送消息
    response = requests.post(webhook_url, json=message)

    # 检查响应
    if response.status_code == 200:
        print("消息发送成功")
    else:
        print("消息发送失败")
        print(response.text)


try:
    # 打开登录页面
    driver.get("https://ticket.wisdommuseum.cn/reservation/userOut/outSingle/toSingleIndex.do")
    # driver.get("https://activity.wisdommuseum.cn/reservation/teamNew/outSpecial/toTeamHome.do")

    # 进行登录操作,填写手机号码、密码和验证码等
    # 请根据实际情况修改下面的代码
    telephone = "**********"
    password = "***********"

    telephone_field = driver.find_element(By.ID, "telephone")
    password_field = driver.find_element(By.ID, "password")
    captcha_field = driver.find_element(By.ID, "code")

    telephone_field.send_keys(telephone)
    password_field.send_keys(password)

    # Manually solve captcha
    captcha_text = input("Enter the captcha: ")  # Manually enter the captcha

    captcha_field.send_keys(captcha_text)

    # 登录按钮点击
    login_button = driver.find_element(By.XPATH, "//input[@type='submit']")
    login_button.click()

    time.sleep(5)
    # 切换到iframe
    driver.switch_to.frame("Conframe")

    # 找到指定日期并点击
    target_date = "2024-4-5"
    date_element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, f"//td[@lay-ymd='{target_date}']")))


    i=1
    # 检查类是否包含"laydate-disabled",如果是,就刷新页面,直到不再包含这个类
    while "laydate-disabled" in date_element.get_attribute("class"):
        print("第" + str(i) + "次刷新")
        # 等待指定日期元素出现
        driver.get("https://ticket.wisdommuseum.cn/reservation/userOut/outSingle/toSingleIndex.do")
        time.sleep(2)
        # Wait for the frame to be available
        WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.ID, "Conframe")))
        date_element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, f"//td[@lay-ymd='{target_date}']")))
        # date_element = driver.find_element(By.XPATH, f"//td[@lay-ymd='{target_date}']")
        i=i+1
        # 使用 JavaScript 来删除元素的 class 属性
        # driver.execute_script("arguments[0].removeAttribute('class');", date_element)



    #提交
    date_element.click()

    # Wait for page to load after date selection
    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "ss")))

    # checkbox 全部设置为选中状态 <input name="ids" type="checkbox" value="24032973">
    checkboxes = driver.find_elements(By.XPATH, "//input[@type='checkbox']")
    # 遍历并选中所有的 checkbox
    for checkbox in checkboxes:
        checkbox.click()

    driver.find_element(By.ID, "ss").click()

    # 找到确认预约按钮并点击
    confirm_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, "layui-layer-btn0")))
    confirm_button.click()

    # 发信息通知我
    # 构建消息内容

    time.sleep(10)
    sendMsg("预约成功")
except Exception as e:
    print(e)

finally:
    # 关闭浏览器
    driver.quit()

注意

需要先去官网录如下预约人信息 验证码也要输一次 然后挂到后台 仅供学习使用 请勿进行非法行为

相关推荐
2603_965148112 小时前
如何解析JSON数据?API返回的商品信息处理教程
开发语言·数据库·python·自动化·json·api
jufeng13073 小时前
【系列:手搓自主 AI Agent:Hermes 架构原理剖析 · 第 8 篇】
python·ai agent·配置系统
circuitsosk4 小时前
跨境电商智能化实战:AI如何赋能客服自动回复、广告智能投放与供应链预测
大数据·人工智能·python·langchain·智能客服
2601_956319884 小时前
2026年零基础学量化:从看懂示例到写清条件和动作
人工智能·python
过期的秋刀鱼!5 小时前
LangChain-D1-模型的工作流程
人工智能·python·langchain
萤火工厂目视化设计5 小时前
智能制造与企业文化目视化浪潮下:中小工厂的机遇与挑战
python·制造
DeepVisionary6 小时前
从GPT-5.6 Sol的Ultrafast模式看推理速度竞赛:750 token/秒背后,Cerebras的晶圆级生意
python·自动化
leisoo80977 小时前
财报数据怎么排雷本地化Python构建财务异常预警系统
人工智能·python·算法
小柯南敲键盘7 小时前
跨马翻译:跨境电商批量图片翻译与视频字幕一站式工具
人工智能·python·音视频
卷无止境8 小时前
FastAPI Guard 全解析,从概念到工程落地的实战指南
后端·python