import os import time import random from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys

def check_browser():

#检查是否已经打开了浏览器
try:
    options = Options()
    options.add_experimental_option("debuggerAddress", "127.0.0.1:9527")
    browser = webdriver.Chrome(options=options)
    browser.execute_script("return true")
    return True
except:
    return False

if name == 'main': if not check_browser(): os.system(r'start chrome --remote-debugging-port=9527 --user-data-dir="D:\评阅用"')

options = Options()
options.add_experimental_option("debuggerAddress", "127.0.0.1:9527")
browser = webdriver.Chrome(options=options)

while True:
    for handle in browser.window_handles:
        browser.switch_to.window(handle)
        if '内蒙古开放大学' in browser.title:
            print('用户登录成功!')
            break
    else:
        time.sleep(1)
        continue
    break

while True:
    try:
        score_box = browser.find_element(By.CLASS_NAME, 'score-box')
        score_input = score_box.find_element(By.TAG_NAME, 'input')
        score_input.clear()
        score_input.send_keys(str(random.randint(94, 99)))
        score_input.send_keys(Keys.ENTER)
        time.sleep(1)
        browser.find_element(By.CLASS_NAME, 'nav-text').click()
    except:
        time.sleep(1)
        continu

原文地址: https://www.cveoy.top/t/topic/g7xc 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录