【某网站的自动刷题代码】

import sys
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
import datetime

iterations = 0
while True:
    iterations += 1

    print(f"Iteration: {iterations}")

    options = Options()
    options.page_load_strategy = 'eager'

    browser = webdriver.Chrome(options=options)
    url = 'h'
    browser.get(url)
    print(browser.title)

    time.sleep(10)
    image_element = browser.find_element(By.XPATH, "/html/body/div[1]/div[1]/div/div[2]/div[2]/img")
    image_element.click()
    time.sleep(2)

    account = browser.find_element(By.XPATH, '//*[@id="signupForm"]/input[1]').send_keys('')
    time.sleep(2)
    password = browser.find_element(By.XPATH, '//*[@id="dlPassword"]').send_keys('')

    submit_button = browser.find_element(By.XPATH, '//*[@id="btnSubmit"]')
    submit_button.click()
    time.sleep(3)
    xuexi = browser.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div[2]/div[2]').click()
    time.sleep(3)
    gengduo = browser.find_element(By.XPATH, '//*[@id="main"]/div[1]/div[2]/div/div[3]/h1/a').click()

    browser.switch_to.window(browser.window_handles[-1])
    time.sleep(2)

    course_duration = browser.find_element(By.XPATH, '//*[@id="listSize"]/li[1]/div[1]/p/span[2]').text
    total_duration = browser.find_element(By.XPATH, '//*[@id="listSize"]/li[1]/div[1]/p/span[3]').text
    time.sleep(2)
    print("课程时长:", course_duration)
    print("累计时长:", total_duration)

    course_duration = course_duration.replace('课程时长:', '')
    total_duration = total_duration.replace('累计学习时长:', '')

    course_duration = datetime.datetime.strptime(course_duration, '%H:%M:%S')
    total_duration = datetime.datetime.strptime(total_duration, '%H:%M:%S')
    total_time_seconds = (course_duration.hour * 3600 + course_duration.minute * 60 + course_duration.second) + \
                         (total_duration.hour * 3600 + total_duration.minute * 60 + total_duration.second)
    print(total_time_seconds)
    time.sleep(3)

    xuexiship = browser.find_element(By.XPATH, '//*[@id="listSize"]/li[1]/div[2]/a').click()

    try:
        button_element = browser.find_element(By.XPATH, '//*[@id="vId0"]/button')
        button_element.click()
        print("Button clicked!")
    except:
        print("Button not found, proceeding to next step...")

    for remaining in range(total_time_seconds, 0, -1):
        sys.stdout.write("\r")
        sys.stdout.write(f"Countdown Timer: {remaining} seconds")
        sys.stdout.flush()
        time.sleep(1)
    print("\nTime's up!")
    browser.quit()

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值