0
点赞
收藏
分享

微信扫一扫

挖掘未来:私有LTE/5G网络驱动智慧矿山的自动化

搬砖的小木匠 04-09 06:30 阅读 2

代码

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

注意

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

举报

相关推荐

0 条评论