Pywinauto自动化操作PC微信提取好友微信号

本文介绍了一种使用 Python 和 pywinauto 库实现微信自动化操作的方法,包括自动化发送消息的功能。通过屏幕截图匹配来定位和操作微信窗口。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

声明:https://zhuanlan.zhihu.com/p/29944988
#
! /usr/bin/env python #coding=utf-8 #pywinauto自动化操作微信号 #by bugscaner http://tools.bugscaner.com import win32clipboard as wc import win32con from pywinauto.application import * from PIL import ImageGrab import time def get_screenxy_from_bmp(main_bmp,son_bmp): #获取屏幕上匹配指定截图的坐标->(x,y,width,height) from PIL import Image img_main=Image.open(main_bmp) img_son=Image.open(son_bmp) datas_a=list(img_main.getdata()) datas_b=list(img_son.getdata()) for i,item in enumerate(datas_a): if datas_b[0]==item and datas_a[i+1]==datas_b[1]: yx=divmod(i,img_main.size[0]) main_start_pos=yx[1]+yx[0]*img_main.size[0] match_test=True for n in range(img_son.size[1]): main_pos=main_start_pos+n*img_main.size[0] son_pos=n*img_son.size[0] if datas_b[son_pos:son_pos+img_son.size[0]] != datas_a[main_pos:main_pos+img_son.size[0]]: match_test=False break if match_test: return (yx[1],yx[0],img_son.size[0],img_son.size[1]) return False def getCopyText(): wc.OpenClipboard() copy_text = wc.GetClipboardData(win32con.CF_TEXT) wc.CloseClipboard() return copy_text oks = [] app = Application().start(r"C:\Program Files (x86)\Tencent\WeChat\WeChat.exe") if not app.windows(): app = Application().connect(path=r"C:\Program Files (x86)\Tencent\WeChat\WeChat.exe") app.window_(title=u"微信",class_name="WeChatMainWndForPC").move_window(0,0) nb = 0 while 1: if nb > 140: break else: nb = nb + 1 app.window_(title=u"微信",class_name="WeChatMainWndForPC").TypeKeys("{DOWN}") time.sleep(.5) pic = ImageGrab.grab((0,0,623,454)) pic.save('1.bmp') ok = get_screenxy_from_bmp(u'1.bmp',u'weixin.bmp') #选中 app.window_(title=u"微信",class_name="WeChatMainWndForPC").double_click_input(coords=(ok[0]+100,ok[1]+10)) #拷贝 app.window_(title=u"微信",class_name="WeChatMainWndForPC").TypeKeys("^c") app.window_(title=u"微信",class_name="WeChatMainWndForPC").click_input(coords=(208,477)) weixin = getCopyText() if weixin not in oks: print weixin oks.append(weixin) f = open("weixin.txt","a") f.write(weixin+"\n") f.close() else: print u"失败一个"

其中的weixin.bmp为截图的微信字体

---------------------------------------分割线2017年11月-------------------------------------

根据以上思路,已实现自动发送微信消息,但是不方便公开,大家可以尝试一下,想想思路。

 

转载于:https://www.cnblogs.com/tianrunzhi/p/7799823.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值