PyAutoGUI最为好用的是其依据屏幕截图进行点击处理,以实现QQ客户端登录为例。
代码如下:
import pyautogui
import time
print(pyautogui.locateOnScreen('QQ.png'))
pyautogui.doubleClick(pyautogui.locateOnScreen('QQ.png'))
time.sleep(15)
oneLocation = pyautogui.locateOnScreen('1.png')
print(oneLocation)
left=oneLocation[0]-10
top=oneLocation[1]+20
width=oneLocation[2]
height=oneLocation[3]
pyautogui.click(x=left,y=top)
pyautogui.write(' 12345678',1)
#password
oneLocation = pyautogui.locateOnScreen('password.png')
print(oneLocation)
pyautogui.click(pyautogui.locateOnScreen('password.png'))
pyautogui.click(x=oneLocation[0]-10,y=oneLocation[1]+20)
pyautogui.write(' 12345678',1)
#login
print(pyautogui.locateOnScreen('login.png'))
pyautogui.click(pyautogui.locateOnScreen('login.png'))
图片素材放在附件中,注意需要根据自己电脑上图片的特点进行替换,否则容易识别出错。