南京博物院自动化预约

代码

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()

注意

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

相关推荐
集成显卡3 小时前
使用 Google 开源 AI 工具 LangExtract 进行结构化信息抽取
python·google·openai
久笙&3 小时前
对象存储解决方案:MinIO 的架构与代码实战
数据库·python·架构
不甘懦弱4 小时前
阿里云搭建flask服务器
服务器·python·flask
赵英英俊4 小时前
Python day51
人工智能·pytorch·python
律品4 小时前
pytest的前置与后置
开发语言·python·pytest
飞翔的佩奇4 小时前
【完整源码+数据集+部署教程】遥感森林砍伐检测系统源码和数据集:改进yolo11-SWC
python·yolo·计算机视觉·数据集·yolo11·遥感森林砍伐检测
阿汤哥的程序之路5 小时前
Python如何将两个列表转化为一个字典
python
RabbitYao5 小时前
Android 项目 通过 AndroidStringsTool 更新多语言词条
android·python
RabbitYao5 小时前
使用 Gemini 及 Python 更新 Android 多语言 Excel 文件
android·python
天天进步20155 小时前
Python机器学习入门:用scikit-learn构建你的第一个预测模型
python·机器学习·scikit-learn