我是靠谱客的博主 认真歌曲,这篇文章主要介绍微信自动化发送消息以及点击,现在分享给大家,希望可以做个参考。

  • 需求来源:公司在更新一些某信数据的时候,总是按照电脑的像素来对为获取,每次部署总需要更新一下代码的位置,为了代码能够更加的严谨,适用于更多的电脑,本次进行了调研更新完善代码
    备注:本次代码仅适用于win环境,因为mac环境缺少某些包,如果是mac请自行调研相关第三方库进行使用

前期准备:
1、python准备,本文在此使用的为3.8.5版本,如有相关问题,请自行问问度娘哦,哈哈
2、第三方库:

复制代码
1
2
3
4
5
6
7
8
9
import re import sys import time import pyperclip from pywinauto.application import Application from pywinauto import mouse import psutil import pyautogui

先关的安装方式也在百度中可以轻松获取到
3、废话也不多说了,直接上代码吧,鞋油备注哦,大家看不懂的可以随时评论区询问

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import re import sys import time import pyperclip from pywinauto.application import Application from pywinauto import mouse import psutil import pyautogui def get_pid(name): """ 根据传入的名称找出对应程序的进程pid """ for proc in psutil.process_iter(): try: pinfo = proc.as_dict(attrs=['pid', 'name']) except psutil.NoSuchProcess: pass else: if pinfo.get('name') == name: return pinfo.get('pid') # 获取控制台打印的东西 class TextArea(object): def __init__(self): self.buffer = [] def write(self, *args, **kwargs): self.buffer.append(args) class Get_url(): """ 微信的点击获取指标 """ def __init__(self) -> None: self.process = get_pid('WeChat.exe') # 查看某个应用的进程 # 常用方式一:连接已有微信进程(进程号在 任务管理器-详细信息 可以查看) self.app = Application(backend='uia').connect(process=self.process) # 拿到微信主窗口 self.win_main_Dialog = self.app.window(class_name='WeChatMainWndForPC') self.win_main_Dialog.draw_outline(colour='red') # 给控件画个红色框便于看出是哪个 self.chat_list = self.win_main_Dialog.child_window(control_type='ListItem', title='文件传输助手') # 选择文件传输助手进行操作 self.chat_list.click_input() # 点击选择的用户进行文本输入,否则会默认当前位置 # chat_list.print_control_identifiers(depth=None, filename=None) # 执行过上一步操作之后在此处进行验证可以打印出相关的信息 super().__init__() def get_url(self, url): """ 获取url进行点击 """ # 输入链接: self.win_main_Dialog.child_window(title='输入').click_input() # 点击输入框 pyperclip.copy(url) pyautogui.hotkey('ctrl', 'v') # 将复制的文字粘贴 self.chat_list.type_keys('~') # 发送 """----------------------------控件位置大小确定----------------------""" # 获取到控件的位置大小 stdout = sys.stdout sys.stdout = TextArea() # 申请的空间 send = self.win_main_Dialog.child_window(title='输入') # 定位到输入框 ,输入库上方的历史记录、截图位置宽度为固定的34 send.print_control_identifiers() # 打印控件信息 text_area, sys.stdout = sys.stdout, stdout # 获取控件信息 coordinates = re.findall('((L.*?))', ''.join([str(i) for i in text_area.buffer]))[0].split(',') # print(coordinates) if '-' in coordinates[0]: value = (int(re.findall('d+', coordinates[0])[0]) - int(re.findall('d+', coordinates[2])[0])) * 0.3 else: value = (int(re.findall('d+', coordinates[2])[0]) - int(re.findall('d+', coordinates[0])[0])) * 0.3 """---------------------------获取坐标位置--------------------------------""" x = int(coordinates[2].replace('R', '')) - value y = int(coordinates[1].replace('T', '')) - 34 * 3 # 因为39为截图列表的宽度,再加一个宽度为链接的位置 mouse.click(button='left', coords=(int(x), int(y))) # 点击事件 # time.sleep(3) exit_colse = self.app.window(class_name='CefWebViewWnd') # 获取打开的窗口 exit_colse.child_window(class_name='Chrome_RenderWidgetHostHWND') if exit_colse.wait('ready', timeout=4): time.sleep(5) self.app.window(class_name="CefWebViewWnd").close() # 关闭窗口 if __name__ == '__main__': get_url = Get_url() # 在此就可以开启大家的循环模式咯 url = '' get_url.get_url(url)

执行完毕之后可以实现某信的自动发送消息到文件传输助手,并实现点击功能
备注:本文存在一个漏洞,当与文件传输助手只有一条时,会点击不到,多发几次就可以了
本文仅用于技术探讨,切勿进行违规操作
技术借鉴:https://www.cnblogs.com/xp1315458571/p/13892205.html#_lab23_0
大家用于处理windows的定位元素的软件也放上了,大家可以自行下载https://download.csdn.net/download/CSDNxiaozhi/44925034

最后

以上就是认真歌曲最近收集整理的关于微信自动化发送消息以及点击的全部内容,更多相关微信自动化发送消息以及点击内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(116)

评论列表共有 0 条评论

立即
投稿
返回
顶部