使用python UIAutomation从QQ2017(v8.9)群界面获取所有群成员详细资料,
2016-01-08 21:26
661 查看
首先安装pip install uiautomation, 再运行本文代码。或者下载https://github.com/yinkaisheng/Python-UIAutomation-for-Windows代码(包含了uiautomation module),直接运行demos目录里的脚本get_qq_group_members.py
uiautomation.py是我写的一个python封装微软UIAutomation API的一个module,使用非常简单
先看我之前一篇文章介绍如何使用 https://www.cnblogs.com/Yinkaisheng/p/3444132.html
首先打开qq群聊天窗口,运行automation.py -a,然后3秒内移动鼠标到qq群上其中一个成员上面(下图右下角红框中),等待打印qq群窗口信息,
可以看到qq群窗口的控件树形结构。
再根据控件结构获取信息,只需60几行代码,如下:
效果图
获取的到QQ群成员详细保存在脚本同一目录@AutomationLog.txt里
代码下载
https://github.com/yinkaisheng/Python-UIAutomation-for-Windows
uiautomation.py是我写的一个python封装微软UIAutomation API的一个module,使用非常简单
先看我之前一篇文章介绍如何使用 https://www.cnblogs.com/Yinkaisheng/p/3444132.html
首先打开qq群聊天窗口,运行automation.py -a,然后3秒内移动鼠标到qq群上其中一个成员上面(下图右下角红框中),等待打印qq群窗口信息,
可以看到qq群窗口的控件树形结构。
再根据控件结构获取信息,只需60几行代码,如下:
#!python3 # -*- coding: utf-8 -*- """ 本脚本可以获取QQ2017(v8.9.4)群所有成员详细资料,请根据提示做对应的操作 作者:yinkaisheng@foxmail.com """ import time import uiautomation as automation def GetPersonDetail(): detailWindow = automation.WindowControl(searchDepth= 1, ClassName = 'TXGuiFoundation', SubName = '的资料') details = '' for control, depth in automation.WalkControl(detailWindow): if isinstance(control, automation.EditControl): details += control.Name + control.CurrentValue() + '\n' details += '\n' * 2 detailWindow.Click(-10, 10) return details def main(): automation.Logger.WriteLine('请把鼠标放在QQ群聊天窗口中的一个成员上面,3秒后获取\n') time.sleep(3) listItem = automation.ControlFromCursor() if listItem.ControlType != automation.ControlType.ListItemControl: automation.Logger.WriteLine('没有放在群成员上面,程序退出!') return consoleWindow = automation.GetConsoleWindow() if consoleWindow: consoleWindow.SetActive() qqWindow = listItem.GetTopWindow() list = listItem.GetParentControl() allListItems = list.GetChildren() for listItem in allListItems: automation.Logger.WriteLine(listItem.Name) answer = input('是否获取详细信息?按y和Enter继续\n') if answer.lower() == 'y': automation.Logger.WriteLine('\n3秒后开始获取QQ群成员详细资料,您可以一直按住F10键暂停脚本') time.sleep(3) qqWindow.SetActive() #确保群里第一个成员可见在最上面 left, top, right, bottom = list.BoundingRectangle while allListItems[0].BoundingRectangle[1] < top: automation.Win32API.MouseClick(right - 5, top + 20) for listItem in allListItems: if listItem.ControlType == automation.ControlType.ListItemControl: if automation.Win32API.IsKeyPressed(automation.Keys.VK_F10): if consoleWindow: consoleWindow.SetActive() input('\n您暂停了脚本,按Enter继续\n') qqWindow.SetActive() listItem.RightClick() menu = automation.MenuControl(searchDepth= 1, ClassName = 'TXGuiFoundation') menuItems = menu.GetChildren() for menuItem in menuItems: if menuItem.Name == '查看资料': menuItem.Click() break automation.Logger.WriteLine(listItem.Name, automation.ConsoleColor.Green) automation.Logger.WriteLine(GetPersonDetail()) listItem.Click() automation.SendKeys('{Down}') if __name__ == '__main__': main() input('press Enter to exit')
效果图
获取的到QQ群成员详细保存在脚本同一目录@AutomationLog.txt里
代码下载
https://github.com/yinkaisheng/Python-UIAutomation-for-Windows
相关文章推荐
- Python中字符串操作函数
- python学习之html从0开始(二)
- python 安装ggplot包
- python中变量类型
- python 中异常处理方式
- Python 2.5.2 迭代
- 自己遇到的python3问题
- python学习之模块
- 【LEETCODE】162-Find Peak Element [Python]
- Python字符串操作
- python通过外部参数发送邮件
- python--列表生成式--8
- 菜鸟学python(5) while语句
- Python+Selenium实现股票板块数据模拟抓取
- python 爬虫(二)
- Python 数据库客户端 DB-API
- Python 日期,时间和函数的使用
- python 浅拷贝(shallow copy) 深拷贝(deep copy)
- 矩阵等式 matrix identity(numpy仿真)
- 一个有用的python装饰器 -- 为执行程序加锁