Click on " Program Life " above, and select "Public Account"
Pay attention to the stories around the programmer (Yuan) for the first time
I have been using WeChat for several years, and there are quite a few WeChat accounts, but do you really know your friends? Which city has the most friends? What is the ratio of male to female friends? What are friends' signatures? Today, let's get to know our WeChat friends fully.
Running platform: Windows
Python version: Python3.6
IDE: Sublime Text
1. Preparation
1.1 Library introduction
The information of WeChat friends can be obtained only by logging in to WeChat. This article uses wxpy , a third-party library, to log in to WeChat and obtain information.
On the basis of itchat , wxpy improves the ease of use of the module through a large number of interface optimizations, and carries out rich function expansion.
Some common scenarios of wxpy:
Control gadgets with open interfaces such as routers and smart homes
Automatically send logs to your WeChat when running the script
Add the group owner as a friend and automatically join the group
Forward messages across numbers or groups
Chat with people automatically
funny
All in all, it can be used to automate various WeChat personal accounts.
1.2 wxpy library installation
wxpy supports Python 3.4-3.6, and version 2.7
Replace "pip" in the command below with "pip3" or "pip2" to ensure installation to the corresponding Python version
Download and install from PYPI official source (may be slow or unstable in China):
pip install -U wxpy
Download and install from the Douban PYPI mirror source ( recommended for domestic users ):
pip install -U wxpy -i "https://pypi.doubanio.com/simple/"
1.3 Login to WeChat
There is a robot object in wxpy, and the robot Bot
object can be understood as a Web WeChat client. Bot
During initialization, the login operation will be performed, and a mobile phone scan is required to log in.
Through Bot
the chats()
, friends()
, groups()
, methods of the robot object, all chat objects , friends , group chats , and public account listsmps()
of the current robot can be obtained respectively .
This article mainly friends()
obtains all friend information and then processes the data.
from wxpy import *
# 初始化机器人,扫码登陆
bot = Bot()
# 获取所有好友
my_friends = bot.friends()
print(type(my_friends))
The following is the output message:
Getting uuid of QR code.
Downloading QR code.
Please scan the QR code to log in.
Please press confirm on your phone.
Loading the contact, this may take a little while.
<Login successfully as 王强