首先安装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几行代码,如下:

#!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 uiautomation选择list内容_使用python UIAutomation从QQ2017(v8.9)群界面获取所有群成员详细资料,...相关推荐

  1. python uiautomation 控件序号_使用python UIAutomation从QQ2016(8.0)群界面获取所有群成员详细资料,...

    automation.py是我写的一个python封装微软UIAutomation API的一个module,使用非常简单 运行automation.py -h查看帮助 首先打开qq群聊天窗口,运行a ...

  2. python uiautomation_使用python UIAutomation从QQ2017(v8.9)群界面获取所有群成员详细资料,...

    首先安装pip install uiautomation, 再运行本文代码.或者下载https://github.com/yinkaisheng/Python-UIAutomation-for-Win ...

  3. python uiautomation选择list内容_蜗牛笔记-文章-UIAutomation运用

    UIAutomation支持多种语言,这里就通过python来调用.UIAutomation是第三方库,所以首先需要安装库pip install uiautomation.先用UIAutomation ...

  4. python uiautomation选择list内容_蜗牛笔记-文章-UIAutomation使用中的问题

    前面以计算器为例子,UIAutomation可以轻松实现.但在实际操作中,不可能就能得到所有元素的唯一属性,很多时候是什么都没有,或者是大家都用一样的名字.这样定位就不容易实现. 以QQMusic为例 ...

  5. python读取文件特定内容_利用python代码获取文件特定的内容,并保存为文档

    import os.path import re # 1 遍历指定目录,显示目录下的所有文件名 def each_file(file_path): path_dir = os.listdir(file ...

  6. python读压缩文件内容_使用Python读写及压缩和解压缩文件的示例

    读写文件 首先看一个例子: f = open('thefile.txt','w') #以写方式打开, try: f.write('wokao') finally: f.close() 文件的打开方式: ...

  7. python如何读取weboutlook内容_用Python通过MAPI读取Outlook中的电子邮件

    我正在尝试编写一个简短的程序,该程序将读取exchange/Outlook配置文件中某个文件夹中电子邮件的内容,以便可以操作数据.但是,我在查找有关python和exchange/Outlook集成的 ...

  8. python删除txt指定内容_使用Python删除文本文件中的部分内容 | 学步园

    为了学习英语,我把从网上下载下来的电影转换成纯MP3文件,放到iTouch里去了,这样就可以直接练习听力了,另外把下载下来的字幕也放进去,听不懂的时候可以看,但有一个问题,网上载下来的字幕格式都如下所 ...

  9. python删除文件部分内容_使用Python删除文本文件中的部分内容

    为了学习英语,我把从网上下载下来的电影转换成纯MP3文件,放到iTouch里去了,这样就可以直接练习听力了,另外把下载下来的字幕也放进去,听不懂的时候可以看,但有一个问题,网上载下来的字幕格式都如下所 ...

最新文章

  1. 如何成为一个合格的项目经理?
  2. 用单片机测量流体流速的_曹阳等:钻井用节流阀抗冲蚀性能的实验评价
  3. 存储块的删除与状态查询
  4. GitHub 五万星登顶,命令行的艺术!
  5. Kubernetes基础:Pod的详细介绍
  6. Hive与数据库的异同
  7. 深入了解学习C++的意义与就业方向
  8. php phpmailer发送邮件
  9. Oracle建立连接的过程分析
  10. IE浏览器不能自动显示PDF文件的解决办法
  11. java简体字转换繁体字_java代码实现简体繁体转换
  12. JavaScript 编写Date 格式化方法『Python风格』
  13. Python保龄球计分Demo
  14. linux什么时候挂载根文件系统,什么时候要重新制作Linux的根文件系统?谢谢
  15. 从五个方面入手保障应用安全
  16. 使用snmpwalk采集设备的OID信息
  17. 4/2 三元表达式/函数递归/匿名函数/内置函数
  18. ubuntu qt编译mysql报错_[Linux]QT编译Mysql驱动(Mariadb驱动),解决qmake报错问题
  19. 干货:嵌入式系统设计开发大全!(万字总结)-道合顺大数据infinigo
  20. 最新版Visual Studio Code下载及远程连接服务器(很详细哦)

热门文章

  1. Spring框架之(无参、有参)构造方法与setter方法的初始化
  2. iOS使用自签名证书实现HTTPS请求
  3. Mongodb 4.0+安装
  4. VMware前路难测,多个厂家群雄逐鹿
  5. redis4.0.6集群部署(5.0.2版本更新补充)
  6. ASP.NET 下载文件方式
  7. Maven项目Spring Boot启动
  8. 基于Vue的小日历(支持按周切换)
  9. Linux6版本系统搭建Open***远程访问
  10. VIM技巧:显示行号