• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

关于python:python实现自动抢课脚本

python 搞代码 4年前 (2022-02-20) 29次浏览 已收录 0个评论

import pyautogui
import time
import xlrd
import pyperclip

定义鼠标事件

duration相似于挪动工夫或挪动速度,省略后则是霎时挪动到指定的地位

def 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 = 1
    while 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("反复{}第{}次".format(img_name, i))
            i = i + 1

cell_value 1.0:左键单击

2.0:输出字符串

3.0:期待

4.0:热键

工作一:进行一轮抢课

def WorkFunction1(sheet):

i = 1
while i < sheet.nrows:
    # 取excel表格中第i行操作
    cmd_type = sheet.cell_value(i, 1)
    # 1:左键单击
    if cmd_type == 1.0:
        # 获取图片名称
        img_name = sheet.cell_value(i, 2)
        retry_times = 1
        if 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("单击左键:{}  Done".format(img_name))
    # 2:输出字符串
    elif cmd_type == 2.0:
        string = sheet.cell_value(i, 2)
        pyperclip.copy(string)
        pyautogui.hotkey('ctrl','v')
        print("输出字符串:{}  Done".format(string))
    # 3:期待
    elif cmd_type == 3.0:
        wait_time = sheet.cell_value(i, 2)
        time.sleep(wait_time)
        print("期待 {} 秒  Done".format(wait_time))
    # 4:键盘热键
    elif cmd_type == 4.0:
        hotkey = sheet.cell_value(i, 2)
        # 避免刷新过快停留在原网页
        time.sleep(1)
        pyautogui.hotkey(hotkey)
        print("按下 {}  Done".format(hotkey))
        time.sleep(1)
    i = i + 1

工作二:蹲点等人退课

def WorkFunction2(sheet) :

while True:
    WorkFunction1(sheet)
    time.sleep(2)

if name == ‘__main__’:

start_time = time.time()
file = "info.xlsx"
# 关上文件
xr = xlrd.open_workbook(filename=file)
# [铂金](https://www.gendan5.com/nmetal/platinum.html)通过索引程序获取表单
sheet = xr.sheet_by_index(0)
print("------欢送应用主动抢课脚本------")
print("---------@danteking---------")
print("1.抢课一次")
print("2.蹲点等人退课后抢指定课")
choice = input(">>")
start_time = time.time()
if choice == "1":
    WorkFunction1(sheet)
elif choice == "2":
    WorkFunction2(sheet)
else:
    print("非法输出,退出")
end_time = time.time()
time_consume = end_time - start_time
time_consume = ('%.2f' % time_consume)
print("耗时 {} 秒".format(time_consume))

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:关于python:python实现自动抢课脚本
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址