网课邦

当前位置:首页 > 网课资讯

网课资讯

智慧树刷课脚本python(智慧树刷课脚本代码)

时间:2025-06-03 02:54:57 作者:暂无作者 浏览量:
内容页左侧

借助pyautogui库,我们可以轻松地控制鼠标、键盘以及进行图像识别,实现自动抢课的功能

1.准备工作

我们在仓库里提供了2个必须的文件,包括:

auto_get_lesson_pic_recognize.py:脚本文件info.xlsx:执行操作信息文件

在运行这个脚本(auto_get_lesson_pic_recognize.py)前,你需要:

1.安装python并成功配置环境变量,可以在cmd下这样检查;若返回版本号,则已安装

python --version1

2.安装以下的依赖,windows用户请以管理员用户运行cmd并依次执行:

pip install pyautoguipip install xlrd==1.2.0pip install pyperclippip install opencv-pythonpip install pillow 12345678910

到此,成功安装了5个库

2.配合使用py脚本和xlsx文件第一步

需要将抢课的每一步所需要点击的图标/超链接在头脑中想清楚

第二步

将抢课每一步的所需点击的图标/超链接截图,保存在和py脚本同一路径下

打开excel表格,根据第一行提示在单元格中进行输入:

A列------备注(可填可不填)B列------操作类型,目前包括:1.左键单击(循环直到找到图片为止):意思就是如果没有找到你设置的那张图片,它就一直找下去,找不到就不停;你所设置的次数是找到成功的次数2.输入字符串3.等待4.热键5.左键单击(无需找到图片):找图片不管找没找到,就找那这么多次,次数=找到成功的次数+找到失败的次数C列------B列的参数待点击图标名(包括图片后缀名,如.png)等待的时间(秒)输入的字符串热键D列------单击重复次数不填,默认为1若想无限单击,填-1

按照你的选课步骤从第2行开始顺序填写excel表格的执行步骤

此时,保存excel表格

第三步

我们打开需要进行操作的选课网页

我们在cmd下切换到脚本所在目录

D:cd xxpython auto_get_lesson_pic_recognize.py12345

根据提示执行即可

上图示例

上图示例

3.auto_get_lesson_pic_recognize功能介绍(1).抢课一次

注意

截图时请随机应变,匹配到图像后,鼠标自动点击图像正中央,建议配合qq截图,ctrl+a/t+a,选取一个独一无二的标记在截图中并且将所要点击的点放在qq截图四个蓝点的中央

截图时请随机应变,匹配到图像后,鼠标自动点击图像正中央,建议配合qq截图,ctrl+a/t+a,选取一个独一无二的标记在截图中并且将所要点击的点放在qq截图四个蓝点的中央

如果遇到同一画面中需要点击的图标存在多个一样的,没有特征参照物,可以在那一步设置等待若干秒,手动点击图标若未成功识别图片,将循环执行识别操作;手动点击图标成功,excel表格中中的指令也会跳到下一条考虑到网络延迟问题,建议合理利用等待功能(2).蹲点捡漏在抢课一次的基础上套了一层死循环巧妙利用f5、左键单击(循环直到找到图片为止)、左键单击(无需找到图片),可以24h挂机实现蹲点捡漏请发挥你的聪明才智,正确截图

4.坐标版本(不建议使用)

坐标版本位于coordinate_version目录下

如果能够确切知道所点击的位置的坐标,可以选用坐标版本

配合qq截图,你能够轻松知道你的鼠标在1920×1080分辨率下在屏幕上的坐标(以像素为单位)

顺序排列单击位置的坐标,实现抢课

excel表格中根据提示填写坐标、操作

5.代码import pyautoguiimport timeimport xlrdimport pyperclipdef Mouse(click_times, img_name, retry_times):if retry_times == 1:location = pyautogui.locateCenterOnScreen(img_name, confidence=0.9)if location is not None:pyautogui.click(location.x, location.y, clicks=click_times, duration=0.2, interval=0.2)elif retry_times == -1:while True:location = pyautogui.locateCenterOnScreen(img_name,confidence=0.9)if location is not None:pyautogui.click(location.x, location.y, clicks=click_times, duration=0.2, interval=0.2)elif retry_times > 1:i = 1while i < retry_times + 1:location = pyautogui.locateCenterOnScreen(img_name,confidence=0.9)if location is not None:pyautogui.click(location.x, location.y, clicks=click_times, duration=0.2, interval=0.2)print(&4;重复{}第{}次&4;.format(img_name, i))i = i + 1def WorkFunction1(sheet):i = 1while i < sheet.nrows:cmd_type = sheet.cell_value(i, 1)if cmd_type == 1.0:img_name = sheet.cell_value(i, 2)retry_times = 1if sheet.cell_type(i, 3) == 2 and sheet.cell_value(i, 3) != 0:retry_times = sheet.cell_value(i, 3)Mouse(1, img_name, retry_times)print(&4;单击左键:{}Done&4;.format(img_name))elif cmd_type == 2.0:string = sheet.cell_value(i, 2)pyperclip.copy(string)pyautogui.hotkey(&9;ctrl&9;,&9;v&9;)print(&4;输入字符串:{}Done&4;.format(string))elif cmd_type == 3.0:wait_time = sheet.cell_value(i, 2)time.sleep(wait_time)print(&4;等待 {} 秒Done&4;.format(wait_time))elif cmd_type == 4.0:hotkey = sheet.cell_value(i, 2)time.sleep(1)pyautogui.hotkey(hotkey)print(&4;按下 {}Done&4;.format(hotkey))time.sleep(1)i = i + 1def WorkFunction2(sheet) :while True:WorkFunction1(sheet)time.sleep(2)if __name__ == &9;__main__&9;:start_time = time.time()file = &4;info.xlsx&4;xr = xlrd.open_workbook(filename=file)sheet = xr.sheet_by_index(0)print(&4;------欢迎使用自动抢课脚本------&4;)print(&4;---------@danteking---------&4;)print(&4;1.抢课一次&4;)print(&4;2.蹲点等人退课后抢指定课&4;)choice = input(&4;>>&4;)start_time = time.time()if choice == &4;1&4;:WorkFunction1(sheet)elif choice == &4;2&4;:WorkFunction2(sheet)else:print(&4;非法输入,退出&4;)end_time = time.time()time_consume = end_time - start_timetime_consume = (&9;%.2f&9; % time_consume)print(&4;耗时 {} 秒&4;.format(time_consume))123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101