1. 程式人生 > >使用python UIAutomation從QQ2017(v8.9)群介面獲取所有群成員詳細資料,

使用python UIAutomation從QQ2017(v8.9)群介面獲取所有群成員詳細資料,

首先安裝pip install uiautomation, 再執行本文程式碼。或者下載https://github.com/yinkaisheng/Python-UIAutomation-for-Windows程式碼(包含了uiautomation module),直接執行demos目錄裡的指令碼get_qq_group_members.py

首先開啟qq群聊天視窗,執行automation.py -a,然後3秒內移動滑鼠到qq群上其中一個成員上面(下圖右下角紅框中),等待列印qq群視窗資訊,
可以看到qq群視窗的控制元件樹形結構。


再根據控制元件結構獲取資訊,只需60幾行程式碼,如下:

#!python3
# -*- coding: utf-8 -*-
"""
本指令碼可以獲取QQ2017(v8.9.4)群所有成員詳細資料,請根據提示做對應的操作
作者:
[email protected]

"""
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裡

程式碼下載

相關推薦

使用python UIAutomationQQ2017(v8.9)介面獲取所有成員詳細資料,

首先安裝pip install uiautomation, 再執行本文程式碼。或者下載https://github.com/yinkaisheng/Python-UIAutomation-for-Windows程式碼(包含了uiautomation module),直接執行demos目錄裡的指令碼get_qq

使用python uiautomation釘釘網頁版提取公司所有聯絡人資訊

之前寫了一個提取QQ群裡所有人資訊的指令碼 https://www.cnblogs.com/Yinkaisheng/p/5114932.html 今天寫一個從釘釘網頁版提取公司所有人通訊錄的指令碼,,本指令碼只支援Firefox瀏覽器,在最新版本Firefox 64上測試通過。 本指令碼是用python3

通過介面獲取所有實現類以及通過註解獲取實現類的思路

近日,工作上被安排修改專案,別人寫的一套內外網同步系統,修改成一套上報下發系統,處理很複雜,在原先那人的基礎上修改了不少原始碼,比較痛苦的是修改他的原始碼,必須要看懂全部程式碼,改的才能順利進行下去,其實這是違反面向物件的一項重要原則——開閉原則,像這樣的程式碼,換個人寫,

Python程式設計入門到實踐》第9章類課後習題(附程式碼)

目錄 9-1(9-2) 餐館 9-3 使用者 9-4 就餐人數 9-5 嘗試登陸次數 9-6 冰淇淋小店 9-7 管理員 9-8 許可權 9-10 匯入Restaurant類 9-11 匯入Admin類 9-12 多個模組​ 9-1(9-2) 餐館

Python程式設計-入門到實戰(習題8-[9-11])

8-9 魔術師:建立一個包含魔術師名字的列表,並將其傳遞給一個名為show_magicians()的函式,這個函式列印列表中每個魔術師的名字。 def show_magicians(magician

Python程式設計入門到實踐》第9章 類

第9章 類 只記錄了自己以前沒有注意到的知識點 1.方法__init__() ​ 這是一個特殊的方法,當你建立例項的時候,Python會自動執行它。在這個方法的名稱中,開頭和末尾各有兩個下劃線,這是一種約定,旨在避免Python預設方法與普通方法發生名稱衝突

Python 程式設計-入門到實踐》9-1~8-17

9-1 餐館:建立一個名為Restaurant的類,其方法_init_()設定兩個屬性:restaurant_name和cuisine_type。建立一個名為describe_restaurant()的方法和一個名為open_restaurant()的方法,其中前者列印前述兩

Beginning Python From Novice to Professional (9) - Socket

gethost code track eth true get ont content socket Socket 小型server: #!/usr/bin/env python import socket s = socket.socket() host = sock

python工具 - 文件名讀取特定信息到excel表格

lis 去掉 test 讀取 span 擴展名 tdi std class 情景:文件名中包含學號和用戶名,其中用戶名在前學好在後,學號為2位,如harry33.txt、natasha12.txt。 要求:將多個文件名中的用戶名與學號分開並保存到excle中。 代碼部分:

python爬蟲入門到放棄(五)之 正則的基本使用

語言 代碼例子 name 添加 iter ima 制表符 imp things 什麽是正則表達式 正則表達式是對字符串操作的一種邏輯公式,就是 事先定義好的一些特定字符、及這些特定字符的組合,組成一個“規則字符”,這個“規則字符” 來表達對字符的一種過濾邏輯。 正則並不是

python爬蟲入門到放棄(六)之 BeautifulSoup庫的使用

src 表達 支持 正則表達 必須 這樣的 com 子節點 prettify 上一篇文章的正則,其實對很多人來說用起來是不方便的,加上需要記很多規則,所以用起來不是特別熟練,而這節我們提到的beautifulsoup就是一個非常強大的工具,爬蟲利器。 beautifulS

python的pexpect模塊獲取信息

python通過pexpect獲取集群主機信息import pexpectip = ‘xx‘cmd = ‘xx‘ssh = pexpect.spawn(‘ssh %s %s‘ %(ip,cmd))r = ssh.read()print r通python的pexpect模塊獲取集群信息

python爬蟲入門到放棄(八)之 Selenium庫的使用

自動 .com 程序 png 都是 例子 等待 點擊 哪些 一、什麽是Selenium selenium 是一套完整的web應用程序測試系統,包含了測試的錄制(selenium IDE),編寫及運行(Selenium Remote Control)和測試的並行處理(Sele

Python error: Microsoft Visual C++ 9.0 is required 解決方案

compile blank 安裝ipython con pan code logs onf pre 換了新電腦,在使用python2.7 pip 安裝ipython時,報錯了 error: Microsoft Visual C++ 9.0 is required. Get

Python爬蟲入門到放棄(十一)之 Scrapy框架整體的一個了解

object 定義 roc encoding eth obi pipe pos 等等 這裏是通過爬取伯樂在線的全部文章為例子,讓自己先對scrapy進行一個整理的理解 該例子中的詳細代碼會放到我的github地址:https://github.com/pythonsite/

Python爬蟲入門到放棄(十三)之 Scrapy框架的命令行詳解

directory xpath idf 成了 spider i386 名稱 4.2 不同的 這篇文章主要是對的scrapy命令行使用的一個介紹 創建爬蟲項目 scrapy startproject 項目名例子如下: localhost:spider zhaofan$ sc

Python爬蟲入門到放棄(十八)之 Scrapy爬取所有知乎用戶信息(上)

user 說過 -c convert 方式 bsp 配置文件 https 爬蟲 爬取的思路 首先我們應該找到一個賬號,這個賬號被關註的人和關註的人都相對比較多的,就是下圖中金字塔頂端的人,然後通過爬取這個賬號的信息後,再爬取他關註的人和被關註的人的賬號信息,然後爬取被關註人

pythonpython開始學編程

python1)變量不需要刪除,可以直接回收使用>>>a = 10 >>>print a.type(a) 10,<type ‘int‘> >>>a = 1.3 >>>print a.type(a) 10,<type ‘

[Spark][Python]spark avro 文件獲取 Dataframe 的例子

imp oca block sql contex local put driver tput [Spark][Python]spark 從 avro 文件獲取 Dataframe 的例子 從如下地址獲取文件: https://github.com/databricks/

Python解決 1到n整數中1出現的次數

很好 time return 面試題 span mas 1=1 大於 獲取 最近在看《劍指Offer》,面試題32的題目:輸入一個整數n,求從1到n這n個整數的十進制表示中1出現的次數。例如輸入12,從1到12這些整數中包含1的數字有1、10、11和12,1