代码分享: from aip import AipOcr import re from PIL import ImageGrab from pymouse import PyMouse APP_ID = '11502394' API_KEY = 'zaY4qOgzI2FdSAEmH7VIPmOn' SECRET_KEY = '50ZBCCxKOAVAV2GqLos47G9VgD9VaZR0' client = AipOcr(APP_ID, API_KEY, SECRET_KEY) string = input("请输入要打劫玩家姓名:") #string = "HC" m = PyMouse() flag = 0 while flag == 0: x1=370 y1=282 x2=460 y2=300 while y1<450: if flag == 1: break bbox = (x1,y1,x2,y2) im = ImageGrab.grab(bbox) im.save('d:/Test_image/test1.png') def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read() image = get_file_content(r'D:\Test_image\test1.png') msg = client.basicAccurate(image) print(msg.get('words_result_num')) if msg.get('words_result_num') is None: x1=370 y1=282 x2=460 y2=300 m.click(570,586) continue s='' for i in msg.get('words_result'): s = s + i.get('words') if string==s: print("匹配成功!正在打劫") flag = 1 #执行打劫操作 m.click(x1+600,y1-20) else: print("匹配失败") y1 = y1 + 123 y2 = y2 + 123 if flag == 0: #刷新操作 m.click(570,586)