码迷,mamicode.com
首页 > 编程语言 > 详细

使用python UIAutomation从QQ2016(8.0)群界面获取所有群成员详细资料,

时间:2016-01-08 21:58:49      阅读:4757      评论:0      收藏:0      [点我收藏+]

标签:

首先到https://github.com/yinkaisheng/Python-UIAutomation-for-Windows下载automation.py和AutomationClient.dll

automation.py是我写的一个python封装微软UIAutomation API的一个module,使用非常简单
运行automation.py -h查看帮助
首先打开qq群聊天窗口,运行automation.py -a,然后3秒内移动鼠标到qq群上其中一个成员上面(下图右下角红框中),等待打印qq群窗口信息,
可以看到qq群窗口的控件树形结构。

技术分享


再根据控件结构获取信息,只需60几行代码,如下:

 1 #!python3
 2 # -*- coding: utf-8 -*-
 3 ‘‘‘
 4 本脚本可以获取QQ2016群所有成员详细资料,请根据提示做对应的操作
 5 作者:yinkaisheng@foxmail.com
 6 2016-01-06
 7 ‘‘‘
 8 import time
 9 import automation
10 
11 
12 def GetPersonDetail():
13     detailWindow = automation.WindowControl(searchDepth= 1, ClassName = TXGuiFoundation, SubName = 的资料)
14     detailPane = automation.PaneControl(searchFromControl= detailWindow, Name = 资料)
15     details = ‘‘
16     for control, depth in automation.WalkTree(detailPane, lambda c: c.GetChildren()):
17         if control.ControlType == automation.ControlType.TextControl:
18             details += control.Name
19         elif control.ControlType == automation.ControlType.EditControl:
20             details += control.CurrentValue() + \n
21     details += \n * 2
22     detailWindow.Click(0.95, 0.02)
23     return details
24 
25 def main():
26     print(请把鼠标放在QQ群聊天窗口中的一个成员上面,3秒后获取\n)
27     time.sleep(3)
28     listItem = automation.ControlFromCursor()
29     if listItem.ControlType != automation.ControlType.ListItemControl:
30         print(没有放在群成员上面,程序退出!)
31         return
32     consoleWindow = automation.GetConsoleWindow()
33     consoleWindow.SetActive()
34     qqWindow = listItem.GetTopWindow()
35     list = listItem.GetParentControl()
36     allListItems = list.GetChildren()
37     for listItem in allListItems:
38         automation.Logger.WriteLine(listItem.Name)
39     answer = input(是否获取详细信息?按y和Enter继续\n)
40     if answer.lower() == y:
41         print(\n3秒后开始获取QQ群成员详细资料,您可以一直按住F10键暂停脚本)
42         time.sleep(3)
43         qqWindow.SetActive()
44         time.sleep(0.5)
45         #确保群里第一个成员可见在最上面
46         left, top, right, bottom = list.BoundingRectangle
47         while allListItems[0].BoundingRectangle[1] < top:
48             automation.Win32API.MouseClick(right - 5, top + 20)
49             time.sleep(0.5)
50         for listItem in allListItems:
51             if listItem.ControlType == automation.ControlType.ListItemControl:
52                 if automation.Win32API.IsKeyPressed(automation.Keys.VK_F10):
53                     consoleWindow.SetActive()
54                     input(\n您暂停了脚本,按Enter继续\n)
55                     qqWindow.SetActive()
56                     time.sleep(0.5)
57                 listItem.Click()
58                 time.sleep(0.5)
59                 listItem.RightClick()
60                 menu = automation.MenuControl(searchDepth= 1, ClassName = TXGuiFoundation)
61                 menuItems = menu.GetChildren()
62                 for menuItem in menuItems:
63                     if menuItem.Name == 查看资料:
64                         menuItem.Click()
65                         break
66                 automation.Logger.WriteLine(listItem.Name, automation.ConsoleColor.Green)
67                 automation.Logger.WriteLine(GetPersonDetail())
68                 listItem.Click()
69                 time.sleep(0.5)
70                 automation.Win32API.SendKeys({Down})
71 
72 
73 if __name__ == __main__:
74     main()
75     input(press Enter to exit)

 

效果图

技术分享

获取的到QQ群成员详细保存在脚本同一目录@AutomationLog.txt里

技术分享

代码下载 https://github.com/yinkaisheng/Python-UIAutomation-for-Windows

使用python UIAutomation从QQ2016(8.0)群界面获取所有群成员详细资料,

标签:

原文地址:http://www.cnblogs.com/Yinkaisheng/p/5114932.html

(1)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!