内蒙古开放大学 自动评分脚本 - Python Selenium
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
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
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 = WebDriverWait(browser, 10).until(EC.presence_of_element_located((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(95, 99)))
nav_wrapper = browser.find_element_by_class_name('nav-wrapper')
nav_wrapper.click()
break
except:
continue
browser.quit()
使用方法:
- 确保你已经安装了 Python 和 Selenium 库。
- 在代码中修改
user-data-dir路径到你的 Chrome 用户数据目录。 - 运行代码。
- 登录内蒙古开放大学账号。
- 脚本会自动找到评分框,输入随机分数,并点击提交按钮。
注意:
- 该脚本仅用于演示目的,请勿用于任何非法活动。
- 使用此脚本可能违反内蒙古开放大学平台的使用条款,请谨慎使用。
- 此脚本仅适用于当前的网页布局,如果网页布局发生变化,脚本可能需要调整。
- 脚本会自动关闭浏览器。
- 请确保你的网络连接稳定。
原文地址: https://www.cveoy.top/t/topic/fYt0 著作权归作者所有。请勿转载和采集!