自动填报成绩机器人 - 内蒙古开放大学
自动填报成绩机器人 - 内蒙古开放大学
这是一个使用 Python 和 Selenium 开发的自动填报成绩机器人,可以帮助用户自动填写内蒙古开放大学的成绩,提高效率。
功能
- 自动登录内蒙古开放大学网站
- 自动填报成绩
- 自动提交成绩
- 运行进度提示
- 支持开始和停止运行
使用方法
- 安装 Python 和 Selenium 库
pip install selenium
-
下载 ChromeDriver 并将其添加到系统环境变量中
-
将代码中的
D:\评阅用替换为您的 Chrome 用户数据目录 -
运行代码
代码
import os
import time
import random
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
import tkinter as tk
from tkinter import messagebox
class ScoreBot:
def __init__(self):
self.browser = None
self.is_running = False
self.root = tk.Tk()
self.root.title('成绩填报机器人')
self.root.geometry('300x150')
self.label = tk.Label(self.root, text='请点击开始运行')
self.label.pack(pady=20)
self.start_button = tk.Button(self.root, text='开始运行', command=self.start)
self.start_button.pack(pady=10)
self.stop_button = tk.Button(self.root, text='停止运行', command=self.stop, state='disabled')
self.stop_button.pack(pady=10)
self.root.protocol("WM_DELETE_WINDOW", self.on_closing)
def on_closing(self):
if self.is_running:
if messagebox.askokcancel("提示", "程序正在运行,确定要退出吗?"):
self.stop()
self.root.destroy()
else:
self.root.destroy()
def check_browser(self):
# 检查是否已经打开了浏览器
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 start(self):
if self.is_running:
return
if not self.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")
self.browser = webdriver.Chrome(options=options)
while True:
for handle in self.browser.window_handles:
self.browser.switch_to.window(handle)
if '内蒙古开放大学' in self.browser.title:
self.label.config(text='用户登录成功!')
break
else:
time.sleep(1)
continue
break
self.is_running = True
self.start_button.config(state='disabled')
self.stop_button.config(state='normal')
self.label.config(text='程序正在运行...')
count = 0
while self.is_running:
try:
score_box = self.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 = self.browser.find_element(By.CLASS_NAME, 'nav-text')
submit_button.click()
time.sleep(2)
except:
continue
else:
if '已到最后' in self.browser.page_source:
self.label.config(text='已到最后,程序停止')
self.stop()
break
count += 1
self.label.config(text='程序正在运行...当前已填报{}个成绩'.format(count))
time.sleep(1)
def stop(self):
self.is_running = False
self.start_button.config(state='normal')
self.stop_button.config(state='disabled')
self.label.config(text='程序已停止')
if __name__ == '__main__':
bot = ScoreBot()
bot.root.mainloop()
注意
- 该代码仅供学习参考,请勿用于任何非法用途
- 使用该代码可能存在风险,请谨慎使用
- 在使用该代码之前,请务必备份您的数据
联系方式
如果您有任何问题或建议,请随时联系我。
版权声明
本代码版权归作者所有,任何形式的转载或修改请注明出处。
原文地址: https://www.cveoy.top/t/topic/fYyv 著作权归作者所有。请勿转载和采集!