Using this program is just to familiarize yourself with the application of the pyautogui module, not all circle articles should be liked, please use it with caution!
We need the pyautogui module, pyautogui is a pure Python GUI automation tool, through which the program can automatically control the mouse and keyboard.
1. Installation
pip3 install pyautogui
You can use it after installation
2. How to find the Moments icon on the screen
First take a screenshot of the circle of friends icon and name it (circle of friends.png), and pyautogui uses functions to match on the screen until an icon is found that is the same as our target icon, and the result is obtained.
# 图像识别(一个)
oneicon = pyautogui.locateOnScreen('朋友圈.png')
The result of recognizing an icon
identify two points
# 图像识别(多个)
multicon = pyautogui.locateAllOnScreen('两个点.png')
After the two points are identified, a result similar to the following (a list) is returned:
[Box(left=985, top=344, width=79, height=49), Box(left=985, top=1322, width=79, height=49)]
This is where the "two dots" (two in the screenshot) are located on the desktop, and returns None if no image is found.
Find the location of the picture and click, and it will be ok.
pyautogui.click(位置)
3. Program
import pyautogui
import time
top = 0 # 屏幕向上滚动的值,可以根据自己屏幕调整
covertop = 500 # 朋友圈封面高度
delay = 0.01
# 寻找各种图片
def findimge(image):
time.sleep(delay) # 延时
if pyautogui.locateOnScreen(image):
left, top, width, height = pyautogui.locateOnScreen(image)
point = pyautogui.center((left, top, width, height))
pyautogui.click(point)
# 找到两点的位置 滚动一个top值
def findtwopoint():
global top
time.sleep(delay)
if pyautogui.locateOnScreen('两个点.png'):
left, top, width, height = pyautogui.locateOnScreen('两个点.png')
point = pyautogui.center((left, top, width, height))
pyautogui.click(point)
def scrool():
global top
global covertop
time.sleep(delay)
if covertop == 0:
pyautogui.scroll(int(-top / 2)) # 滚动鼠标滚轮
else:
pyautogui.scroll(-top + covertop)
covertop = 0
if __name__ == "__main__":
findimge('朋友圈.png')
while True:
findtwopoint()
findimge('赞.png')
scrool()
4. Run:
Open the computer version of WeChat and maximize the window
run the program
Existing problems: If you click like, you will click again if you are on the current screen. If you can detect that you have already clicked, just scroll over and it will be ok.