一個(gè)很簡(jiǎn)單的腳本,用途是實(shí)現(xiàn)微信小程序或其他軟件的自動(dòng)化操作,如果是長(zhǎng)期固定需求,可以考慮把腳本內(nèi)置到常用軟件的環(huán)境中,比如MAYA,當(dāng)我每天打開MAYA時(shí)就可以實(shí)現(xiàn)每天自動(dòng)在小程序上疫情打卡
主要使用pyautogui和opencv模塊,opencv用于圖像識(shí)別,pyautogui用于鍵鼠操作文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-502334.html
import pyautogui as pgi
import time
import cv2
此處設(shè)置為相對(duì)路徑,運(yùn)行前提前將小程序圖標(biāo)截圖放在這個(gè)路徑下命名為daka.jpg文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-502334.html
# 尋找桌面圖標(biāo):
# 用opencv識(shí)別桌面圖像,并與路徑中的圖像比對(duì),輸出中心點(diǎn)。
# pyautogui.locateonscreem也可以識(shí)別屏幕,但是識(shí)別對(duì)分辨率要求較高,差一個(gè)像素點(diǎn)都會(huì)導(dǎo)致錯(cuò)誤,返回none,采用opencv直接識(shí)別,大部分情況都會(huì)返回一個(gè)結(jié)果(不一定是目標(biāo)結(jié)果)
def findProc(img_path):
pgi.screenshot().save(r'.\img\screenshot.png')
img = cv2.imread(r'.\img\screenshot.png')
img_terminal = cv2.imread(r'.\img\daka.jpg')
height = img_terminal.shape[0]
width = img_terminal.shape[1]
result = cv2.matchTemplate(img, img_terminal, cv2.TM_SQDIFF_NORMED)
upper_left = cv2.minMaxLoc(result)[2]
center = (int(upper
到了這里,關(guān)于pyautogui微信小程序自動(dòng)化操作的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!