Python 淘宝联盟-佣金设置 批量设置佣金和服务费


import json
import os
import cv2
import time
import numpy as np
import win32gui, win32ui, win32con
from matplotlib import pyplot as plt
from ctypes import windll
from PIL import Image
from pymouse import PyMouse
from PIL import ImageGrab
import threading
import copy
import pyautogui
import win32api
import pyautogui




# 类 图片处理 ----------------------------------------------------------------------
class PicClass:
    
    bigImg=None# 大图
    
    # 图片识别返回坐标数组 参数:小图模板 相似度(阈值) 大图(可为空)
    def getPointByImg(self, template, threshold, newBigImg=None):
        arr=[]
        img_rgb=None
        if newBigImg is None:
            img_rgb=copy.deepcopy(self.bigImg)
        else:
            img_rgb=copy.deepcopy(newBigImg)                
        img_gray=cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)# 灰度处理
        h, w=template.shape[:2]
        res=cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
        loc=np.where(res >= threshold)
        for pt in zip(*loc[::-1]):
            right_bottom=(pt[0] + w, pt[1] + h)
            cv2.rectangle(img_rgb, pt, right_bottom, (0, 0, 255), 2)            
            center_point=(int(pt[0]+w/2), int(pt[1]+h/2))# 中心点
            arr.append(center_point)
            left2=(center_point[0]-2,center_point[1]-2)
            right2=(center_point[0]+2,center_point[1]+2)
            cv2.rectangle(img_rgb, left2, right2, (0, 255, 0), 2)            
        return arr

    # 图片识别 参数:大图路径 小图路径
    def getPointByPath(self, bigImgPath, smartImgPath):
        newBigImg=cv2.imread(bigImgPath)
        template=cv2.imread(smartImgPath, 0)
        threshold=0.8
        self.bigImg=newBigImg
        return self.getPointByImg(template, threshold, newBigImg)

    # 描点
    def paintPoint(self, arr, saveResImgPath=None):        
        img_rgb=copy.deepcopy(self.bigImg)# 1. 读入原图和模板
        img_gray=cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)    
        for center_point in arr:                     
            w=4
            left2=(center_point[0]-w,center_point[1]-w)
            right2=(center_point[0]+w,center_point[1]+w)
            cv2.rectangle(img_rgb, left2, right2, (0, 255, 0), 2)                
        if saveResImgPath!=None:
            cv2.imwrite(saveResImgPath, img_rgb)# 保存处理后的图片
        return img_rgb
        
   
# 截屏
def screenshots():
    img1=ImageGrab.grab()
    curTime=time.strftime('%Y-%m-%d %H%M%S',time.localtime(time.time()))
    fileName=curTime+'.jpg'
    img1.save(fileName)
    return fileName



# 图片识别 点击文本框 输入数字
#time.sleep(2)

picObj=PicClass()
bigImgPath=screenshots()# 截屏
#bigImgPath='big.jpg'# 用于测试 模拟大图
arr=picObj.getPointByPath(bigImgPath, 'smart.jpg');# 图片匹配
picObj.paintPoint(arr, '2.jpg')# 绘点
print(arr)

def testClick():
    for index, value in enumerate(arr):
        print(value)
        print(index)
        x=value[0]
        y=value[1]
        pyautogui.click(x, y)# 模拟点击
        time.sleep(0.1)
        if index%2 == 0:
            pyautogui.typewrite('22')# 第一列 佣金
        else:
            pyautogui.typewrite('3')# 第二列 服务费
        

testClick()






#win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL,0,0,-500)# 滚动网页





原文地址:https://www.cnblogs.com/guxingy/p/12559276.html