Pynput自动化操作示例

import openpyxl as px
import sys

import time

wb = px.load_workbook("D:/abc.xlsx")
ws = wb.active

def openEntWx():
    from pynput.mouse import Button, Controller
    mouse = Controller()
    #鼠标移到目标app上
    mouse.position = (1173, 884)

    #单击以点开
    #mouse.click(Button.left)
    mouse.press(Button.left)
    mouse.release(Button.left)

    #鼠标移到上
    mouse.position = (23, 152)
    time.sleep(1)

    #单击以点开
    mouse.press(Button.left)
    mouse.release(Button.left)

    #鼠标移到上
    mouse.position = (127, 147)

    #单击以点开
    mouse.press(Button.left)
    mouse.release(Button.left)
    time.sleep(1)

def addClient():
    from pynput.mouse import Button, Controller

    mouse = Controller()

    #鼠标移到“添加”上
    mouse.position = (1370, 42)

    #单击以点开
    mouse.press(Button.left)
    mouse.release(Button.left)
    time.sleep(1)
    
    #鼠标移到“添加”输入框上
    mouse.position = (582, 339)

    #单击
    mouse.press(Button.left)
    mouse.release(Button.left)

def inputEntWx(words):
    from pynput.keyboard import Key, Controller
    #键盘输入
    keyboard = Controller()
    keyboard.type(words)
    time.sleep(1)

def confirmInput():
    from pynput.mouse import Button, Controller    
    mouse = Controller()

    '''
    #鼠标移到绿色箭头上
    mouse.position = (874, 339)

    #单击
    mouse.press(Button.left)
    mouse.release(Button.left)
    time.sleep(2)
    '''

    #鼠标移到“添加”上
    mouse.position = (830, 448)
    
    #单击
    mouse.press(Button.left)
    mouse.release(Button.left)
    time.sleep(1)

    #鼠标移到“发送”上
    mouse.position = (744, 480)
    
    #单击
    mouse.press(Button.left)
    mouse.release(Button.left)
    time.sleep(1)

    #这个位置是出现异常时的关闭按钮
    mouse.position = (873, 360)
    mouse.press(Button.left)
    mouse.release(Button.left)
    time.sleep(1)

    #关闭对话框
    mouse.position = (898, 266)
    #单击
    mouse.press(Button.left)
    mouse.release(Button.left)
    time.sleep(1)


openEntWx()

m = 0
for i in range(1, ws.max_row +1 ):
    if ws.cell(i, 3).value != "已添加":
        tel = ws.cell(i, 2).value
        print(tel)
        
        addClient()
        inputEntWx(tel)
        confirmInput()
        
        time.sleep(1)
        ws.cell(i, 3).value = "已添加"
        wb.save("D:/abc.xlsx")
        m += 1
        print(m)
        if m >= 30:             #设定退出条件为完成一定工作量
            break
            sys.exit()
    else:
        pass

    

需要注意的是,上述pynput鼠标位置参数,均与各人电脑屏幕大小相关,请自行测试修正。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值