我做了个能自动帮我刷课的代码,只需要提前把相关按钮截图就可以运行了,话不多说,来看看代码吧~
# @撰写人: 符力丰
# @时间: 2024/9/23 13:54
# @版本: 1.0
# @引用: None
# @原理简述: None
import time
import pyautogui
import keyboard
def click(picture, confidence=0.95):
_ = pyautogui.locateCenterOnScreen(picture, confidence=confidence)
if _ is not None:
pyautogui.click(_, duration=1)
else:
print(f"Can't find picture <{picture}>, please click by yourself.\n"
f"click <space> to continue.\n")
keyboard.wait('space')
class Wisdom_tree: # 智慧树刷课
def Init(self):
pyautogui.scroll(300, 800, 800)
pyautogui.moveTo(800, 850)
pyautogui.moveTo(800, 800)
def next_video(self):
pyautogui.move(-20, 0, duration=0.5)
click('picture/nextvideo.png')
pyautogui.click(800, 800, duration=3)
def speedup(self):
if self.shows('picture/X1.png', confidence=0.8):
pyautogui.moveTo(pyautogui.locateCenterOnScreen('picture/X1.png', confidence=0.8), duration=0.5)
click('picture/X1.5.png', confidence=0.8)
return True
return False
def auto_reply(self):
for i in ('A', 'B', 'C', 'D'):
click(f'picture/choose{i}.png')
if self.shows('picture/right.png'):
break
if self.shows('picture/wrong.png'):
click(f'picture/choose{i}.png')
click('picture/close.png')
pyautogui.click(800, 800, duration=1)
def shows(self, picture, confidence=0.95):
_ = pyautogui.locateOnScreen(picture, confidence=confidence)
if _ is not None:
return True
return False
running = True
def Break():
global running
running = False
a = Wisdom_tree()
keyboard.add_hotkey('ctrl+space', Break)
print('》》》请在5秒内打开视频学习界面\n'
'》》》(ctrl+空格)退出程序\n')
time.sleep(5)
speed = False
while running:
a.Init() # 每次初始化确保页面在最上方
if a.shows('picture/finish.png') or a.shows('picture/finish2.png', confidence=0.98): # 判断是否播放结束
a.next_video()
speed = False
if not speed: # 修改倍速
speed = a.speedup()
if a.shows('picture/question.png'): # 自动尝试回答随堂弹出的问题
a.auto_reply()
注意这个在不同的平台,不同的课程都需要修改代码哦~~
~(> w <)~