# 微信好友信息爬取+数据可视化,在‘ 保护我方鲁班八号’朋友代码上优化
# encoding=utf-8
__author__ = 'wind'
__location__ = '上海'
__date__ = '2020-04-22'
from wxpy import *
import re
import jieba
import numpy
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import imageio
from wordcloud import WordCloud,ImageColorGenerator
from matplotlib.patches import Polygon
from matplotlib.colors import rgb2hex
from mpl_toolkits.basemap import Basemap
# 微信登录
def wx_login():
try:
#初始化机器人,扫码登录
bot = Bot()
#获取好友列表
frinds = bot.friends()
#wxpy.api.chats.chats.Chats对象是多个聊天对象的合集,
# 可用于搜索或统计,可以搜索和统计的信息包括sex(性别)、province(省份)、city(城市)和signature(个性签名)等
print(type(frinds))
#输出好友列表
for i in frinds:
print(i)
except Exception as e:
print(e.args)
wx_login()
return frinds
# 数据可视化
#统计男女性别信息
def wx_friend_sex_infor(friends):
sex_dict = {
'male':0,'female':0,'other':0}
for friend in friends:
if friend.sex == 1:
sex_dict['male'] += 1
elif friend.sex == 2:
sex_dict['female'] += 1
else:
print(friend,'性别未标记!')
sex_dict['other'] += 1
print(sex_dict)
wx_show_sex_infor(sex_dict)
# pie(x, explode=None, label
利用python统计微信通讯录信息
最新推荐文章于 2024-04-17 09:47:09 发布