Python data analysis (1) - get the statistics of WeChat friends

This article is mainly to try the next interesting python module: wxpy After importing this module, it is very convenient to create a WeChat robot and do some interesting analysis related to WeChat .

1. wxpy installation

First, install via pip and enter in command line mode:

pip install -U wxpy

As shown below:

write picture description here

write picture description here

2. Log in to WeChat

(1) Import the wxpy module first, and then set the login mode . As follows:

#导入模块
from wxpy import *

'''
微信机器人登录有3种模式,
(1)极简模式:robot = Bot()
(2)终端模式:robot = Bot(console_qr=True)
(3)缓存模式(可保持登录状态):robot = Bot(cache_path=True)
'''
#初始化机器人,选择缓存模式(扫码)登录
robot = Bot(cache_path=True)

After running the above code, you will be prompted to take out your mobile phone and scan the code to confirm the login . As shown below:

write picture description here

3. Get WeChat friend information

The complete code looks like this:

# -*- coding: utf-8 -*-
"""
Created on Sun Aug 20 14:53:54 2017

@author: Administrator
"""

#导入模块
from wxpy import *

'''
微信机器人登录有3种模式,
(1)极简模式:robot = Bot()
(2)终端模式:robot = Bot(console_qr=True)
(3)缓存模式(可保持登录状态):robot = Bot(cache_path=True)
'''
#初始化机器人,选择缓存模式(扫码)登录
robot = Bot(cache_path=True)

#获取好友、群、公众号信息
robot.chats()

#获取好友的统计信息
Friends = robot.friends()
print(Friends.stats_text())

The statistics of WeChat friends are shown in the following figure:

write picture description here

The above is just a basic analysis for WeChat friends, and more detailed ones will need to be further explored by yourself.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325351062&siteId=291194637