一、安装库
pip install psutil
pip install pywinauto
二、代码
import psutil #psutil 用于获取微信电脑版的进程信息
import pywinauto#pywinauto 用于自动化控制微信电脑版
from pywinauto.application import Application
PID = 0
print("获取微信进程id")
for proc in psutil.process_iter():
try:
pinfo = proc.as_dict(attrs=['pid', 'name'])
except psutil.NoSuchProcess:
print("没有打开微信")
pass
else:
if 'WeChat.exe' == pinfo['name']:
PID = pinfo['pid']
print("找到微信进程")
print("用PyWinAuto 实例化一个应用")
app = Application(backend='uia').connect(process=PID)
print("打开微信朋友圈")
win = app['微信']
pyq_btn = win.child_window(title="朋友圈", control_type="Button")
cords = pyq_btn.rectangle()
pywinauto.mouse.click(button='left', coords=(cords.left + 10, cords.top + 10))
print("打开微信朋友圈完成")
pyq_win = app['朋友圈']
print(pyq_win.dump_tree())
三、操作
1、先打开电脑微信最大化
2、运行程序
3、结果