1.png
2.png
3.png
4.png
5.png
6.png
import pyautogui #导入鼠标键盘库
import time
#进入微信
WX_location=pyautogui.locateCenterOnScreen('1.png',confidence=0.9)
#查找精确度为1.0,即百分之百精准匹配——这其实很不方便,实际我们把精确度设为0.9更科学,既能保证不会找错对象,又不会因为默认的精确度太苛刻,明明对象存在代码却找不到而返回None
pyautogui.click(WX_location.x,WX_location.y,clicks=2,interval=0.1,duration=0.2,button="left")#点击次数默认是1
while True:
Logon_location=pyautogui.locateCenterOnScreen('2.png',confidence=0.9)
if Logon_location is not None:
pyautogui.click(Logon_location.x,Logon_location.y,clicks=1,interval=0.2,duration=0.2,button="left")#点击次数默认是1
break
print("未找到匹配图片,0.1秒后重试")
time.sleep(0.1)
#进入朋友圈
while True:
Circle_location=pyautogui.locateCenterOnScreen('3.png',confidence=0.9)
if Circle_location is not None:
pyautogui.click(Circle_location.x,Circle_location.y,clicks=1,interval=0.2,duration=0.2,button="left")#点击次数默认是1
break
print("未找到匹配图片,0.1秒后重试")
time.sleep(0.1)
#进入点赞界面
while True:
Comment_location=pyautogui.locateCenterOnScreen('4.png',confidence=0.9)
if Comment_location is not None:
pyautogui.click(Comment_location.x,Comment_location.y,clicks=1,interval=0.2,duration=0.2,button="left")#点击次数默认是1
break
print("未找到匹配图片,0.1秒后重试")
time.sleep(0.1)
#点赞
roll = -100
while True:
Like_location=pyautogui.locateCenterOnScreen('5.png',confidence=0.9)
Liked_location=pyautogui.locateCenterOnScreen('6.png',confidence=0.9)
if Liked_location is not None:
while True:
pyautogui.scroll(roll) # 向下滚动100
Comment_location = pyautogui.locateCenterOnScreen('4.png', confidence=0.9)
if Comment_location is not None:
pyautogui.click(Comment_location.x, Comment_location.y, clicks=1, interval=0.2, duration=0.2,button="left")
break
print("未找到匹配图片,0.1秒后重试")
time.sleep(0.5)
roll=roll-500
elif Like_location is not None:
pyautogui.click(Like_location.x, Like_location.y, clicks=1, interval=0.2, duration=0.2,button="left")
else:
while True:
Comment_location = pyautogui.locateCenterOnScreen('4.png', confidence=0.9)
if Comment_location is not None:
pyautogui.click(Comment_location.x, Comment_location.y, clicks=1, interval=0.2, duration=0.2,
button="left") # 点击次数默认是1
break
print("未找到匹配图片,0.1秒后重试")
time.sleep(0.1)
参考:
哔哩哔哩: up主 不开心就喝水 的代码