今天是工作日,就不写太多了,简单写一下上周末学习到的新库wxpy的一些微信朋友统计功能,给各位参考学习一下。(我用的是python3)
1)首先肯定是要安装啦~
直接在本机状态下命令窗口敲入:pip install -U wxpy
2)扫码登陆个人微信
from wxpy import *
bot = Bot(cache_path=True)
3)统计微信朋友人数top10省份
friends_stat = bot.friends().stats()
friend_loc = [ ] #每一个元素是一个二元列表,分别存储地区和人数信息
for province, count in friends_stat["province"].items():
if province != "":
friend_loc.append([province, count])
# 对人数倒序排序
friend_loc.sort(key=lambda x: x[1], reverse=True)
# 打印人数最多的10个地区
for item in friend_loc[:10]:
print (item[0], item[1])
4)统计微信朋友人数top10城市
friend_loc = [ ]
for city, count in friends_stat["city"].items():
if city != "":
friend_loc.append([city, count])
friend_loc.sort(key=lambda x: x[1], reverse=True)
for item in friend_loc[:10]:
print (item[0], item[1])
5)统计微信朋友性别分布
for sex, count in friends_stat["sex"].items():
# 1代表MALE, 2代表FEMALE
if sex == 1:
print ("MALE %d" % count)
elif sex == 2:
print ("FEMALE %d" % count)
6)用excel画出来
—End—