山东电专--自动化刷课

免责声明:本文仅用于学习和研究目的,不鼓励或支持任何非法活动。所有技术内容仅供个人技术提升使用,未经授权不得用于攻击、侵犯或破坏他人系统。我不对因使用本文内容而引起的任何法律责任或损失承担责任。

如有任何违法,请求资源过量等问题均与本人无关!

目录

项目地址

环境

浏览器

超级鹰

运行截图

源码


项目地址

26255/Sddl_auto: 山东电专自动化刷课

原理:网页自动化对页面功能点(查看页面)发起请求.


环境

  1. 操作系统:Windows, macOS 或 Linux 都可以,依赖于你的浏览器和驱动配置。
  2. Python 版本 :3.6 及以上。(建议3.10.x) Python Releases for Windows | Python.org
  3. 所需库:
    • requests:用于处理 HTTP 请求。
    • selenium:用于浏览器自动化操作。
    • tkinter:用于 GUI 界面。
    • hashlib:用于 MD5 加密。
  1. 浏览器:Chrome 浏览器。

  2. ChromeDriver:与你的 Chrome 浏览器版本匹配的驱动。

  3. 超级鹰---账号,密码,软件ID 超级鹰验证码识别-专业的验证码云端识别服务,让验证码识别更快速、更准确、更强大

    python -V
    pip install requests selenium

    找2个版本对应的下载: https://googlechromelabs.github.io/chrome-for-testing/
    (chrome chromedriver)

    注册超级鹰(注册关注公众号免费送积分,生成软件ID)
    https://www.chaojiying.com/


浏览器

超级鹰


运行截图

路径用反斜杠转义!

D:\\chrome-win64\\chrome-win64\\chrome.exe



源码

项目用pyinstaller打包

python 复制代码
import requests
from hashlib import md5
import tkinter as tk
from tkinter import messagebox
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time
from concurrent.futures import ThreadPoolExecutor

# Chaojiying_Client 类
class Chaojiying_Client(object):
    def __init__(self, username, password, soft_id):
        self.username = username
        password = password.encode('utf8')
        self.password = md5(password).hexdigest()
        self.soft_id = soft_id
        self.base_params = {
            'user': self.username,
            'pass2': self.password,
            'softid': self.soft_id,
        }
        self.headers = {
            'Connection': 'Keep-Alive',
            'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
        }

    def PostPic(self, im, codetype):
        """图片识别"""
        params = {
            'codetype': codetype,
        }
        params.update(self.base_params)
        files = {'userfile': ('ccc.jpg', im)}
        r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, files=files, headers=self.headers)
        return r.json()

# Selenium 自动化脚本
def process_href(href, driver):
    print(href + '成功')
    driver.get(href)
    time.sleep(2)

def start_script():
    chrome_path = chrome_path_entry.get()   # Chrome浏览器的路径
    chrome_driver_path = chrome_driver_path_entry.get() # Chrome WebDriver的路径
    username = username_entry.get() # 电专账号
    password = password_entry.get() # 电专密码
    chaojiying_username = chaojiying_username_entry.get()   #超级鹰账号
    chaojiying_password = chaojiying_password_entry.get()   #超级鹰密码
    chaojiying_soft_id = chaojiying_soft_id_entry.get()     #超级鹰-软件ID

    if not chrome_path or not chrome_driver_path or not username or not password or not chaojiying_username or not chaojiying_password or not chaojiying_soft_id:
        messagebox.showerror("错误", "请填写所有字段")
        return

    # 设置浏览器
    chrome_options = webdriver.ChromeOptions()
    chrome_options.binary_location = chrome_path
    service = Service(chrome_driver_path)
    driver = webdriver.Chrome(service=service, options=chrome_options)

    try:
        driver.get("https://elearning.sepcedu.com/login")
        time.sleep(4)

        # 登录操作
        driver.find_element(By.CLASS_NAME, 'el-input__inner').send_keys(username)
        time.sleep(2)
        driver.find_element(By.XPATH, '//input[@type="password"]').send_keys(password)
        time.sleep(2)

        # 获取验证码并识别
        driver.find_element(By.XPATH, '//img').screenshot('logo.png')
        chaojiying = Chaojiying_Client(chaojiying_username, chaojiying_password, chaojiying_soft_id)
        im = open('./logo.png', 'rb').read()
        code = chaojiying.PostPic(im, 3004)['pic_str']
        driver.find_element(By.XPATH, '//input[@placeholder="请输入验证码"]').send_keys(code)
        time.sleep(1)

        # 点击登录
        driver.find_element(By.XPATH, '//button').click()
        time.sleep(2.5)

        # 进入我的学习
        driver.find_element(By.XPATH, '//li[@class="el-menu-item"][1]').click()
        time.sleep(1.7)
        start_window = driver.current_window_handle

        # 获取所有课程
        div_s = driver.find_elements(By.XPATH, '//div[@class="courseItem"]')
        for div in div_s:
            pro = div.find_element(By.XPATH, './/div[@class="el-progress-bar__innerText"]/span')
            if pro.text != "100%":
                print(pro.text)
                an = div.find_element(By.XPATH, './/div[@class="enterCourse"]')
                an.click()
                time.sleep(1)

                win = driver.window_handles
                driver.switch_to.window(win[1])
                time.sleep(3)

                # 展开菜单并点击按钮
                try:
                    zk = driver.find_element(By.XPATH, '//a[@class="section-collapsemenu collapsed"]')
                    zk.click()
                    time.sleep(1)
                except Exception as e:
                    print("展开菜单时发生异常", e)
                    pass
                try:
                    buttons = driver.find_elements(By.XPATH, '//button[@class="btn btn-outline-secondary btn-sm text-nowrap"]')
                    for button in buttons:
                        button.click()
                        time.sleep(0.9)
                except:
                    pass

                # 获取学习链接
                links = driver.find_elements(By.XPATH, '//ul[@data-for="cmlist"]//li[@data-indexed="true"]//a[@class=" aalink stretched-link"]')
                href_list = [link.get_attribute('href') for link in links if link.get_attribute('href').startswith('https')]
                # 线程池,并发请求。
                with ThreadPoolExecutor(max_workers=10) as executor:
                    executor.map(lambda href: process_href(href, driver), href_list)
                    time.sleep(0.5)

                driver.close()
                driver.switch_to.window(win[0])

        print('='*45)
        print("圆满结束")
        print("温馨提示:需要自己提交和学习的作业还需要自己去做哦~~~")
        time.sleep(50)
        driver.close()

    finally:
        driver.quit()

# 创建主窗口
root = tk.Tk()
root.title("山东电专刷课自动化脚本")

# 创建输入字段
tk.Label(root, text="Chrome路径:").grid(row=0, column=0)
chrome_path_entry = tk.Entry(root, width=50)
chrome_path_entry.grid(row=0, column=1)

tk.Label(root, text="ChromeDriver路径:").grid(row=1, column=0)
chrome_driver_path_entry = tk.Entry(root, width=50)
chrome_driver_path_entry.grid(row=1, column=1)

tk.Label(root, text="用户名:").grid(row=2, column=0)
username_entry = tk.Entry(root, width=50)
username_entry.grid(row=2, column=1)

tk.Label(root, text="密码:").grid(row=3, column=0)
password_entry = tk.Entry(root, width=50, show="*")
password_entry.grid(row=3, column=1)

tk.Label(root, text="超级鹰账号:").grid(row=4, column=0)
chaojiying_username_entry = tk.Entry(root, width=50)
chaojiying_username_entry.grid(row=4, column=1)

tk.Label(root, text="超级鹰密码:").grid(row=5, column=0)
chaojiying_password_entry = tk.Entry(root, width=50, show="*")
chaojiying_password_entry.grid(row=5, column=1)

tk.Label(root, text="超级鹰软件ID:").grid(row=6, column=0)
chaojiying_soft_id_entry = tk.Entry(root, width=50)
chaojiying_soft_id_entry.grid(row=6, column=1)

# 创建开始按钮
start_button = tk.Button(root, text="开始", command=start_script)
start_button.grid(row=7, column=0, columnspan=2)

# 运行主循环
root.mainloop()

相关推荐
liqingdi4378 分钟前
[SWPUCTF 2023 秋季新生赛]Easy SMC
服务器·前端·javascript
仿生joe会梦见漫天的大雪吗11 分钟前
CTF Misc 工具选型指南:按题型分类的工具、原理与限制
后端·安全
QYR-分析20 分钟前
工业安全无线遥控器:5.4% 稳步增长,起重与移动机械的安全控制终端
安全
自养Agent37 分钟前
MCP Server Boundary Audit Report
linux·服务器·人工智能·windows·大模型·llm
Initialize-le38 分钟前
systemd 服务起不来?五步排查法
前端·chrome
派小心.1 小时前
网站统计采样数据的误差核对
大数据·服务器·前端·数据库·人工智能·小程序·数据分析
A心有千千结2 小时前
通过 SSH 反向代理让服务器借用本机网络访问 GitHub 的最佳实践
linux·服务器·网络·git·ssh·github
fengkai45452 小时前
十三、Zabbix 监控
运维·服务器·zabbix·监控·网络设备
数字新视界2 小时前
机房动环监控助力智能管理
大数据·服务器·数据库·动环监控系统·动力与环境监控系统
算力小木3 小时前
#标题:5090 vs 4090D 到底差多少?我拿八卡实测了一周
服务器