程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Pythons latest method to crawl the circle of friends!!

編輯:Python

In a few years ago , There was once a model on the Internet Create a circle of friends photo album Products . But its process is very different :

  • First , The specified micro signal needs to be added , And give this micro signal permission to view your circle of friends ;
  • then , Wait a few hours ;
  • Last , Get a link , Inside, the album template shows the content of your circle of friends ;

It sounds awesome at first , I wonder how this product gets personal circle of friends data , Until you see its usage process, you first need to add wechat friends , Instantly smiled and understood .

Actually , The circle of friends has always been the territory that many people's reptiles want to collect . Before , The circle of friends can only be on the mobile phone or Pad Check out , To get data on your circle of friends ,** Or manually copy human flesh , Or handle it with a hook .

** One of these two operations is too low-end , One is too high-end .

Is there anything a little simpler ?** use Appnium Maybe it's a way , It's much easier to operate than a hook , however ,Appnium Environment configuration of , Will scare away many friends .

** therefore ,Appnium Or the threshold is slightly higher .

Until recently , The wechat computer version began to support the circle of friends , Things seem to be turning around !

So you can go through PyWinAuto and PyAutoGui These two tools , Realize the automatic control and data acquisition of desktop programs .

These two tools , Can it be applied to the collection of wechat circle of friends data ?

First , Introduce the required libraries :

1. `import psutil`
2. `import pywinauto`
3. `from pywinauto.application import Application`

among :

  • psutil It is used to obtain the process information of wechat computer version ;
  • pywinauto For automatic control of wechat computer version

then , We go through psutil The process of getting wechat computer program from the library ID:

1. `PID = 0`
2. `for proc in psutil.process_iter():`
3. `try:`
4. `pinfo = proc.as_dict(attrs=['pid', 'name'])`
5. `except psutil.NoSuchProcess:`
6. `pass`
7. `else:`
8. `if 'WeChat.exe' == pinfo['name']:`
9. `PID = pinfo['pid']`

This process ID To provide to PyWinAuto To connect to wechat computer version . then , use PyWinAuto Instantiate an application :

1. `app = Application(backend='uia').connect(process=PID)`

Then control the wechat computer version , Open the circle of friends window :

1. `win = app[' WeChat ']`
2. `pyq_btn = win.child_window(title=" Circle of friends ", control_type="Button")`
3. `cords = pyq_btn.rectangle()`
4. `pywinauto.mouse.click(button='left', coords=(cords.left + 10, cords.top + 10))`

Above code , And that's what happened Python Code control wechat computer version opens the window of circle of friends . The effect is as follows :

The window of the circle of friends is open , What if you get the data inside ?

We use first .dump_tree() Method to see how the structure of each control in the circle of friends window is :

1. `print(pyq_win.dump_tree())`

This will print the structure of all displayed components in the circle of friends window to the console , The displayed content is shown in the figure below :

Let's take a concrete example , For example, this message in the circle of friends :

It's in dump_tree() The structure in is as follows :

You can see , Every message in the window , such as Name of the contact Circle of friends content Circle of friends release time And so on are composed of various components .

We can get and control these components , To achieve data extraction . For example, in this case , We can locate Edit This component to get the content of this circle of friends :

Compared with other tools , Is it extremely simple ?

It's not just simple , The effect is very good .

Interested friends , Try it now !

At the end of the article

What's your opinion on the article , Or any technical problems , Welcome to leave a message and discuss in the comment area !


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved