用pyautogui库写了个自动看视频的程序
本帖最后由 yjptx121 于 2020-12-21 22:43 编辑import pyautogui as pg
import time
class Page_turnig:
""" 执行顺序为:移动到初始坐标,开始点击->移动到下一课点击,点击完成以后执行翻页,再次回到初始坐标,以此循环"""
def __init__(self):
self.speed = 1
self.initialize = # 初始坐标
self.time_1 = 1 # 翻页循环初始化
self.time_2 = 1 # 页内循环初始化
self.list_time = [
,
,
] # 课程列表
def move_(self): # 横向坐标和纵向坐标
"""移动鼠标到指定位置"""
pg.moveTo(self.initialize, self.initialize, self.speed) # 移动到指定坐标
# pg.click() # 点击鼠标
coordinates = pg.position() # 获取当前坐标并赋值输出
print(f'当前坐标为{coordinates}')
def read_cir(self, index):
"""页内循环"""
print(f'移动至初始坐标 --> {self.initialize}, {self.initialize}, 执行read_cir()...')
for each in index: # 这是每个页面的课程列表
Page_turnig.move_(self)
print(f'【INFO】:执行第 {self.time_1} 页第 {self.time_2} 次阅读,下一次点击将在{each*60} 秒后!')
time.sleep(each*60)
# time.sleep(7)
self.initialize += 42
self.time_2 += 1
self.time_2 = 1
self.initialize = # 循环完成后初始化,便于执行下一次循环
def page_cir(self):
"""翻页循环"""
for each in range(len(self.list_time)):
Page_turnig.read_cir(self, self.list_time)
self.time_1 += 1
click_mouse() # 翻页
time.sleep(2)
print('程序结束!')
def click_mouse(): # 拉动列表,拉动14次差不多就翻页了
"""鼠标点击次数"""
for k in range(14):
pg.click(1300, 686) # 移动到指定位置点击鼠标
def run():
start = Page_turnig()
start.page_cir()
if __name__ == '__main__':
run()
页:
[1]