python 淘宝联盟_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)# 滚动网页

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值