山东电专--自动化刷课

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

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

目录

项目地址

环境

浏览器

超级鹰

运行截图

源码


项目地址

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

相关推荐
真智AI1 小时前
构建安全的机器学习推理API:基于FastAPI的用户认证与管理实战
安全·机器学习·fastapi
胡耀超2 小时前
内网渗透技术全面指南——安全业务视角(基于《内网渗透技术 (吴丽进、苗春雨 主编;郑州、雷珊珊、王伦 副主编)》)
linux·windows·安全·web安全·网络安全·内网渗透·安全治理
yjsstar2 小时前
Linux的web服务器的部署及优化
linux·运维·服务器
运维有小邓@3 小时前
比较入站和出站防火墙规则
服务器·网络·php
TPBoreas3 小时前
Ubuntu开放端口
linux·服务器·网络
晴天Y283 小时前
基于LVS实现负载均衡,对NAT模式的介绍和使用案例
服务器·负载均衡·lvs
西门吹雪@1323 小时前
阿里云服务器-centos部署定时同步数据库数据-dbswitch
服务器·数据库·阿里云
IT专业服务商4 小时前
DELL R770 服务器,更换OCP模块!
运维·服务器·硬件架构·硬件工程·开闭原则
群联云防护小杜4 小时前
如何有效防御服务器DDoS攻击
运维·服务器·前端·tcp/ip·安全·ddos
FreeBuf_4 小时前
CVE体系若消亡将如何影响网络安全防御格局
大数据·安全·web安全