itchat分析微信好友的个性签名
itchat分析微信好友的个性签名
itchat是一个开源的微信个人号python接口(公众号、企业号接口为itchatmp)。使用它可以非常优雅地操纵个人微信号。文档链接
七夕到了,博主也要自娱自乐呀,“不知其人视其友“,为了对自己有更全面的了解,博主决定分析一下微信好友的个性签名。
安装
pip install itchat
实验原理
- 使用itchat接口采集好友数据
- 对好友性别进行统计分析,使用echart可视化展示
- 对好友的个性签名文本汇总,然后使用结巴分词法分词,最后用词云显示
采集好友数据
def getFriendsData():
itchat.login() #这里需要扫码登录
friends = itchat.get_friends()
return friends #返回一个JSON对象
性别分析
性别统计
#统计性别比例
def sexStatistic(friends):
male = 0
female = 0
other = 0
for friend in friends:
sex = friend['Sex']
if sex==1:
male += 1
elif sex==2:
female += 1
else:
other += 1 #出现other的原因是有些用户会不填写性别
total = len(friends)
male,female,other = map(lambda x:x*1.0/total,[male,female,other])
displaySex(male,female,other,friends[0]['NickName']) #friends[0]['NickName']是登录者的名字(就是博主)
显示性别比
为了使数据更加直观,这里使用百度的echart库,echart本是JavaScript的数据可视化库,这里使用它的python接口
pip install echarts-python
def displaySex(male,female,other,user):
from echarts import Echart, Legend, Pie
chart = Echart(u'%s的微信好友性别比例'%user, 'from WeChat')
chart.use(Pie('WeChat',[
{'value': male, 'name': u'男性 %.2f%%' % float(male*100)},
{'value': female, 'name': u'女性 %.2f%%' % float(female*100)},
{'value': other, 'name': u'其他 %.2f%%' % float(other*100)}],
radius=["50%", "70%"]))
chart.use(Legend(["male", "female", "other"]))
chart.plot()
运行结果会在浏览器中显示()
嗯,男女比还算协调。
个性签名分析
文本获取
def signatureStatistic(friends):
import sys #设置编码
reload(sys)
sys.setdefaultencoding('utf-8')
text = u''
for friend in friends:
signature = friend['Signature'].strip()
if len(signature)>0 and not signature.startswith('<span'):
text += friend['Signature']+' '
displayWordCloud(text) #使用词云显示
词云分析
这里用到了结巴分词法。值得注意的是要过滤掉诸如”我“、”的“、“因为”、”就是“等无实际意义的stopword,网上可以找到中文的常见stopword列表
def displayWordCloud(text):
import jieba #结巴中文分词
import wordcloud #词云库
from scipy.misc import imread #从scipy借用读取图片的模块
import matplotlib.pyplot as plt #matplotlib纯粹用来辅助作图
from collections import Counter
#结巴分词
jiebaText = list(jieba.cut(text,cut_all=True))
#过滤stopword
stopWords = open('./stopWord.txt').read().strip().split()
jiebaText = [x for x in jiebaText if len(x)>0 and x not in stopWords]
# 使用 counter 做词频统计,并转成字典
wordDic = dict(Counter(jiebaText))
bgimg = imread("./mask.jpg") # 返回numpy.ndarray类型的rgb数组
myWordCloud = wordcloud.WordCloud(
font_path="./font.otf", #特别注意,中文一定要有支持中文的字体,默认是没有的,要从外部引入
background_color = "#242424", #背景色设置
mask=bgimg, #词云的"模子",是一个数组
width=1200,
height=1200,
)
#生成词云图
myWordCloud.generate_from_frequencies(wordDic)
plt.imshow(myWordCloud)
plt.axis("off")
plt.show()
词云分析结果
最后,祝我的好友们七夕快乐~
itchat分析微信好友的个性签名的更多相关文章
- [置顶]
Python 使用itchat 对微信好友数据进行简单分析
人生苦短,我用Python! Python 热度一直很高,我感觉这就是得益于拥有大量的包资源,极大的方便了开发人员的需求. 最近在一个微信公众号上看到一个调用微信 API 可以对微信好友进行简单数据分 ...
- 利用 Python 分析微信好友性别和位置
今天用到一个非常有意思的库——itchat,它已经完成了 wechat 的个人账号API接口,使爬取个人微信信息更加方便. 下载 爬取微信好友信息 这样就将你所有微信好友的信息都返回了,我们并不需要 ...
- 使用itchat获取微信好友的男女比例
# 使用itchat获取微信好友的男女比例 import itchat itchat.auto_login(hotReload=True) friends = itchat.get_friends(u ...
- Python使用itchat获取微信好友信息~
最近发现了一个好玩的包itchat,通过调用微信网页版的接口实现收发消息,获取好友信息等一些功能,各位可以移步itchat项目介绍查看详细信息. 目标: 获取好友列表 统计性别及城市分布 根据好友签名 ...
- Python分析微信好友性别比例和省份城市分布比例
如需转发请注明:小婷儿的博客:https://www.cnblogs.com/xxtalhr/p/10642241.html 一.安装模块 pip install itchat pip install ...
- 10分钟教你用Python玩转微信之抓取好友个性签名制作词云
01 前言+展示 各位小伙伴我又来啦.今天带大家玩点好玩的东西,用Python抓取我们的微信好友个性签名,然后制作词云.怎样,有趣吧~好了,下面开始干活.我知道你们还是想先看看效果的. 后台登录: 词 ...
- 【python】itchat登录微信获取好友签名并生成词云
在知乎上看到一篇关于如何使用itchat统计微信好友男女比例并使用plt生成柱状图以及获取微信好友签名并生成词云的文章https://zhuanlan.zhihu.com/p/36361397,感觉挺 ...
- python itchat 爬取微信好友信息
原文链接:https://mp.weixin.qq.com/s/4EXgR4GkriTnAzVxluJxmg 「itchat」一个开源的微信个人接口,今天我们就用itchat爬取微信好友信息,无图言虚 ...
- 使用 python 进行微信好友分析
使用 python 进行微信好友分析 1. 使用到的库 ① wxpy:初始化微信机器人 ② openpyxl:保存微信好友数据为Excel表格 ③ pyecharts:生成可视化的地图 ④ wordc ...
随机推荐
- Git强制拉取覆盖本地
1.多条执行 git fetch --all git reset --hard origin/master git pull 2.单条执行 git fetch --all && git ...
- [转] Javascript中理解发布--订阅模式
发布订阅模式介绍 发布---订阅模式又叫观察者模式,它定义了对象间的一种一对多的关系,让多个观察者对象同时监听某一个主题对象,当一个对象发生改变时,所有依赖于它的对象都将得到通知. 现实生活中的发布- ...
- Django时区的解释
https://segmentfault.com/q/1010000000405911
- python全栈开发day69-cookie、session
一.ORM回顾 1. 内容回顾 1. Django中使用ORM连接MySQL的步骤: 1. 创建数据库 2. 告诉Django连接哪个数据库 在settings.py中设置数据库相关的链接信息 3. ...
- redcontrol for SL 中文化及样式选择
app.xaml.cs public partial class App: Application { public App() { //指定t ...
- root用户无法通过ssh连接Linux系统
ssh协议为了安全,有些版本默认禁止root用户的登陆 cd /etc/ssh 编辑sshd_config文件 cat sshd_config | grep PermitRootLogin Permi ...
- Codeforces 1017F The Neutral Zone (看题解)
这题一看就筛质数就好啦, 可是这怎么筛啊, 一看题解, 怎么会有这么骚的操作. #include<bits/stdc++.h> #define LL long long #define f ...
- Linux Centos7安装最新anslib
一.添加最新epel源 yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 二.添加最 ...
- 51Nod1231 记分牌 动态规划
原文链接https://www.cnblogs.com/zhouzhendong/p/51Nod1231.html 题目传送门 - 51Nod1231 题意 题解 显然是一个竞赛图相关的题. 我们首先 ...
- Java中文字符所占的字节数
Java语言中,中文字符所占的字节数取决于字符的编码方式,一般情况下,采用ISO8859-1编码方式时,一个中文字符与一个英文字符一样只占1个字节:采用GB2312或GBK编码方式时,一个中文字符占2 ...