山东电专--自动化刷课

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

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

目录

项目地址

环境

浏览器

超级鹰

运行截图

源码


项目地址

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

相关推荐
云和数据.ChenGuang17 分钟前
自动化运维工程师之ansible启动rpcbind和nfs服务
运维·服务器·运维技术·数据库运维工程师·运维教程
yimengsama19 分钟前
VMWare虚拟机如何连接U盘
linux·运维·服务器·网络·windows·经验分享·远程工作
松涛和鸣22 分钟前
32、Linux线程编程
linux·运维·服务器·c语言·开发语言·windows
Xの哲學1 小时前
Linux NAT 深度剖析: 从设计哲学到实现细节
linux·服务器·网络·架构·边缘计算
Dxy12393102161 小时前
Python的正则表达式入门:从小白到能手
服务器·python·正则表达式
小周学学学1 小时前
vSphere DRS与vSphere HA
运维·服务器·vmware·虚拟化
德迅云安全—珍珍2 小时前
主机安全-德迅卫士
linux·服务器·安全
咕噜企业分发小米2 小时前
如何平衡服务器内存使用率和系统稳定性?
java·服务器·前端
2301_805962932 小时前
Windows连接腾讯云服务器
服务器·windows·腾讯云
云动课堂2 小时前
一键升级 OpenSSH 10到最新版:告别手工编译、兼容国产系统、批量部署无忧!
linux·服务器·centos