Read QQ messages using Python

Read QQ messages using Python

Read QQ messages using Python

After the last article "Using Python to automatically send QQ messages" was published, many friends were very interested. Some friends also asked if there was a way to get QQ messages, and whether it was necessary to use screen capture or OCR methods?

Actually, it is not necessary. Microsoft has defined a set of interfaces, UI Automation, to automate the testing of interfaces or provide them to accessible software for people with disabilities to use Windows programs. Since it can automate the testing of interfaces, it means that it can get everything in the interface. Otherwise, how can it be tested?

However, not all software supports UIA. Software from large foreign companies or programs using standard interfaces all support it. In order to facilitate the use of software by people with disabilities, supporting this interface is mandatory or recommended by law in some countries. However, there are no relevant regulations in China, and almost no domestic software supports it. However, Tencent's QQ actually supports it!

Tencent's software is still very good, at least in China it is still very standardized. I'll put a lightning rod first, maybe Tencent will delete this article one day.

Thanks to yin kaisheng for uiautomation, which makes UIA encapsulation so easy to use.

First install the required libraries

  1. pip install uiautomation

Then open the QQ message window. This is just a demonstration. It would be more troublesome to open the message window using a program, so I won’t introduce it here.

#Import required libraries

  1. import uiautomation as auto

#Find the message window. The ClassName of the message window is 'TXGuiFoundation', but the class name of the QQ main window is also this. So we need to add another parameter Name='哈哈' to distinguish them. This is the name of the message window, which is the same as the other party's QQ nickname.

  1. qq_win = auto.WindowControl(searchDepth=1, ClassName= 'TXGuiFoundation' , Name = 'Haha' )

#First try to find the edit box where the message is entered to see if you can get the text inside. If the QQ window is merged, there may be multiple edit boxes. In this case, you need to set the foundIndex of the EditControl function to get other edit boxes.

  1. input_edit = qq_win.EditControl()
  2. print(input_edit. Name )
  3. print(input_edit.GetValuePattern().Value) #Print the text in the edit box

#Historical messages in QQ are a list, and the list will have many Children. The Name of the Children is the text part of the historical message.

  1. msg_list = qq_win.ListControl() #Find the list
  2. items = msg_list.GetChildren()
  3. for one_item in items: #Traverse all Children
  4. print(one_item. Name ) #print message

Now you can see the effect.

This example is just a simplified example, please try it. Maybe this article will be deleted one day. Please follow me! Save it! Thank you!!

<<:  Will base station signal radiation affect health?

>>:  Tencent Weibo is officially closed: Currently unable to log in, users can apply for personal content backup

Recommend

Be careful if your phone shows these 4 symptoms! It may be dangerous!

If your phone has the following features This cou...

How to promote 360 ​​advertising information flow?

360 Promotion uses professional media promotion a...

Your Guide to YouTube Video Ad Formats for 2020!

Video marketing and brand promotion through YouTu...

Do you really know how to recall users? 10% recall in just 3 steps!

The user life cycle of each product is a process ...

User growth: How to achieve distribution fission?

The development of the Internet has passed the tr...

The top ten e-books are free and completed, and the fantasy novels are ranked?

Due to the epidemic, many people are bored at hom...

Tik Tok promotion and operation | Practical skills of Tik Tok short videos!

With the rise of short videos such as Douyin, sho...

In-depth analysis: the underlying logic of user needs

In the ups and downs of the business world, there...

Man sues bank after girlfriend secretly shops online

A young man born in the 1980s found that the paym...

Will weather outside the Earth affect human life? | World Space Week

Throughout the ages, with a desire to explore the...

"Twenty-four, sweep the house"! Dust and cloth, don't miss these corners →

The Spring Festival is approaching, and every hou...