菜鸟:pyautogui代码

Noob: pyautogui code

我对编程的学习还处于起步阶段。 我最近玩了 python,想用 pyautogui 做一个关于 GUI 自动化的小项目。这个想法是制作一个非常基本和简单的 Instagram 自动化程序,双击等待随机的秒数(选择以便不超过 "per hour rate" 这样的最大值)然后滚动并无限重复。 这是我到目前为止得到的:

#instaclicker-bot
import pyautogui 
import random
while True
    pyautogui.moveTo(500,500,duration=0,25) #move cursor over image in webbrowser
    pyautogui.doubleClick(500,500) #doubleclick to "like"
    waittime = random.radInt(20,40) #wait between 20 and 40 seconds to emulate random behaviour
    print "waiting for %d seconds" % waittime #print chosen wait time
    time.sleep(waittime) #wait for chosen wait time
    pyautogui.scroll(500) #scroll to position mouse over next picture below

我总是遇到语法错误和 "Indent block detected" 错误。另外,变量的使用是否正确?

我很清楚任何类型的机器人和自动化都违反 Instagram 的使用条款。我不打算以任何不好的方式使用它。这对我来说只是一个有趣的项目。

这也是我第一次post/asking求助堆栈交换,希望我没有犯任何愚蠢的错误,如果我做错了,请提前道歉。

在此先感谢您的帮助!

也许试试这样的方法。

random.radint == 2

random.randint(1, 10) == 1

代码中存在几个语法错误和编译时错误。

  • while True替换为while True:


  • 替换pyautogui.moveTo(500,500,duration=0,25) pyautogui.moveTo(500,500,25,duration=0) 因为在 python 中,非
    关键字参数不能跟在关键字参数之后。 (参考this)

  • waittime = random.radInt(20,40)替换为等待时间=<br> random.randint(20,40)

  • 最后是 import time.

我建议使用像 cloud9 这样的 IDE,这样可以快速反馈这些错误。