山东电专--自动化刷课

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

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

目录

项目地址

环境

浏览器

超级鹰

运行截图

源码


项目地址

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()

相关推荐
运维小杨1 小时前
Docker的安装,服务器与客户端之间的通信
服务器·docker·容器
希赛网2 小时前
希赛《华为 HCIA-Datacom 》核心考点之 NAT 技术解析
运维·服务器·网络·计算机网络·智能路由器·华为认证
机器视觉知识推荐、就业指导2 小时前
手动开发一个TCP服务器调试工具(二):无界面 TCP 通信服最小实现
服务器·网络协议·tcp/ip
Gobysec4 小时前
Goby 漏洞安全通告| NestJS DevTools /inspector/graph/interact 命令执行漏洞(CVE-2025-54782)
安全
胖大和尚5 小时前
ssh 公钥连接服务器失败,排查方向
运维·服务器·ssh
可变羽翼核心8 小时前
Steam饥荒联机版多人服务器搭建全解析 -- 阿里云Linux系统构建云服务器
linux·运维·服务器
是垚不是土10 小时前
JumpServer 堡垒机全流程搭建指南及常见问题解决方案
运维·安全·网络安全·github·系统安全·创业创新
心勤则明10 小时前
JVM(Java虚拟机)运行时数据区
java·jvm·chrome
小孙姐11 小时前
Linux-Day12.DNS服务
linux·运维·服务器
小孙姐11 小时前
Linux-Day07.磁盘空间管理
linux·运维·服务器