自动评分工具 - 内蒙古开放大学 - 自动评分脚本
import os import time import random import tkinter as tk from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By
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
def run_program(): global running running = True status_label.config(text='程序正在运行') 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:
break
else:
time.sleep(1)
continue
break
while running:
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)))
time.sleep(1)
submit_button = browser.find_element(By.CLASS_NAME, 'nav-text')
submit_button.click()
time.sleep(2)
except:
continue
else:
if '已到最后' in browser.page_source:
status_label.config(text='已到最后,请手动保存后重新开始!')
break
time.sleep(1)
status_label.config(text='程序已停止')
def stop_program(): global running running = False status_label.config(text='程序已停止')
if name == 'main': running = False
root = tk.Tk()
root.title('自动评分—100')
root.geometry('300x200')
start_button = tk.Button(root, text='开始运行', command=run_program)
start_button.pack(pady=10)
stop_button = tk.Button(root, text='停止运行', command=stop_program)
stop_button.pack(pady=10)
status_label = tk.Label(root, text='说明:第一次启动会比较慢,浏览器可以最小化')
status_label.pack(pady=10)
root.mainloop()
原文地址: https://www.cveoy.top/t/topic/fYHi 著作权归作者所有。请勿转载和采集!