python 爬取微信好友列表和个性签名,绘制个性签名云图
python爬取微信好友列表和个性签名,绘制个性签名云图
1. 简要介绍
本次实验主要用到下面几个库 :
1)itchat---用于微信接口,实现生成QR码,用于微信扫描登陆
2)re(正则化)---由于微信好友个性签名含有中英文,本次只提取中文,需要使用re模块去除其他无关字符
3)wordcloud(云图)---使用该模块生成中文云图
4)jieba(中文分词)--- 号称最好的中文分词工具
2. 安装库
pip install re
pip install jieba
pip install itchat
pip install wordcloud
3. 实验代码
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2018/1/19 14:37
# @Author : Z.C.Wang
# @Email :
# @File : spider_wechat.py
# @Software: PyCharm Community Edition
"""
Description :
"""
import re
import jieba
import itchat
from pandas import DataFrame
import matplotlib.pyplot as plt
from wordcloud import WordCloud, ImageColorGenerator
import numpy as np
import PIL.Image as Image
import pickle def get_var(var):
variable = []
for i in friends:
value = i[var]
variable.append(value)
return variable def list2str(wordlist):
string = ' '
for word in wordlist:
string = string + ' ' + word
return string if __name__ == '__main__':
itchat.login()
friends = itchat.get_friends(update=True)
male = female = other = 0
for i in friends[1:]:
sex = i['Sex']
if sex == 1: male += 1
elif sex == 2: female += 1
else: other += 1
total = len(friends[1:])
# print('男性好友:%.2f%%' % float(male/total*100))
# print('女性好友:%.2f%%' % float(female/total*100))
# print('不明性别好友:%.2f%%' % float(other/total*100))
Nickname = get_var('NickName')
Sex = get_var('Sex')
Province = get_var('Province')
print(Province)
City = get_var('City')
Signature = get_var('Signature')
data = {'Nickname': Nickname, 'Sex': Sex, 'Province': Province,
'City': City, 'Signature': Signature}
pickle.dump(data, open('data.txt', 'wb'))
frame = DataFrame(data)
frame.to_csv('info.csv', index=True, encoding='utf-8-sig') siglist = []
for i in friends:
signature = i['Signature'].strip().replace('spam', '').replace('class', '').replace('emoji', '')
# rep = re.compile('1f\d+\w*|[<>/=]')
rep = re.compile("[^\u4e00-\u9fa5^]")
signature = rep.sub('', signature)
siglist.append(signature)
text = ''.join(siglist)
wordlist = jieba.cut(text, cut_all=True)
wordlist = list(wordlist)
String = list2str(wordlist) coloring = np.array(Image.open('alice.png'))
my_wordcloud = WordCloud(background_color='white', max_words=2000,
mask=coloring, max_font_size=55, random_state=42,
scale=2, font_path=r'C:\Windows\Fonts\simhei.ttf').generate(String)
image_colors = ImageColorGenerator(coloring)
plt.imshow(my_wordcloud.recolor(color_func=image_colors))
plt.imshow(my_wordcloud)
plt.axis('off')
plt.show()
4. 实验结果


python 爬取微信好友列表和个性签名,绘制个性签名云图的更多相关文章
- 我用 Python 爬取微信好友,最后发现一个大秘密
前言 你身处的环境是什么样,你就会成为什么样的人.现在人们日常生活基本上离不开微信,但微信不单单是一个即时通讯软件,微信更像是虚拟的现实世界.你所处的朋友圈是怎么样,慢慢你的思想也会变的怎么样.最近在 ...
- Python爬取微信好友
前言 今天看到一篇好玩的文章,可以实现微信的内容爬取和聊天机器人的制作,所以尝试着实现一遍,本文记录了实现过程和一些探索的内容 来源: 痴海 链接: https://mp.weixin.qq.com/ ...
- python itchat 爬取微信好友信息
原文链接:https://mp.weixin.qq.com/s/4EXgR4GkriTnAzVxluJxmg 「itchat」一个开源的微信个人接口,今天我们就用itchat爬取微信好友信息,无图言虚 ...
- Python3 爬取微信好友基本信息,并进行数据清洗
Python3 爬取微信好友基本信息,并进行数据清洗 1,登录获取好友基础信息: 好友的获取方法为get_friends,将会返回完整的好友列表. 其中每个好友为一个字典 列表的第一项为本人的账号信息 ...
- python爬取微信小程序(实战篇)
python爬取微信小程序(实战篇) 本文链接:https://blog.csdn.net/HeyShHeyou/article/details/90452656 展开 一.背景介绍 近期有需求需要抓 ...
- Python爬取微信小程序(Charles)
Python爬取微信小程序(Charles) 本文链接:https://blog.csdn.net/HeyShHeyou/article/details/90045204 一.前言 最近需要获取微信小 ...
- python爬取微信公众号
爬取策略 1.需要安装python selenium模块包,通过selenium中的webdriver驱动浏览器获取Cookie的方法.来达到登录的效果 pip3 install selenium c ...
- Python:爬取乌云厂商列表,使用BeautifulSoup解析
在SSS论坛看到有人写的Python爬取乌云厂商,想练一下手,就照着重新写了一遍 原帖:http://bbs.sssie.com/thread-965-1-1.html #coding:utf- im ...
- 使用Python爬取微信公众号文章并保存为PDF文件(解决图片不显示的问题)
前言 第一次写博客,主要内容是爬取微信公众号的文章,将文章以PDF格式保存在本地. 爬取微信公众号文章(使用wechatsogou) 1.安装 pip install wechatsogou --up ...
随机推荐
- Bootstrap popover源码分析
/* ======================================================================== * Bootstrap: popover.js ...
- Bootstrap Dropdown 源码分析
/* ======================================================================== * Bootstrap: dropdown.js ...
- 00020970-0000-0000-C000-000000000046
00020970-0000-0000-C000-000000000046 System.InvalidCastException: 无法将类型为“Microsoft.Office.Interop.Wo ...
- BZOJ_1576_[Usaco2009 Jan]安全路经Travel&&BZOJ_3694_最短路_树链剖分+线段树
Description Input * 第一行: 两个空格分开的数, N和M * 第2..M+1行: 三个空格分开的数a_i, b_i,和t_i Output * 第1..N-1行: 第i行包含一个数 ...
- 5 Application 对象
5.1鸟瞰Application对象 5.2 必须了解的面向显示特性 5.2.1 使用ScreenUpdating改进和完善执行性能 代码清单5.1:实现屏幕更新的性能 '代码清单5.1: 实现屏幕更 ...
- RDA 工模
1.工模GUI如下图: 注意两个API接口,_APP_Update_Layer()/UpdateNodeFunctionContent() 这两个接口一个是刷新ListView,另一个刷新ListVi ...
- Eclipse中执行sql脚本文件
转自:https://blog.csdn.net/weixin_37778823/article/details/79614281 在Eclipse中导入或新建sql脚本文件(.sql文件),选择指定 ...
- MySql 5.7 Archive 版本安装失败 解决过程
下载地址 https://dev.mysql.com/downloads/mysql/5.7.html#downloads 按照网络教程: 创建my.ini 文件,并填写配置内容: [mysql] # ...
- E20180120-hm
derive vt. 得到,导出; 源于,来自; (从…中) 提取; hierarchy n. [计] 分层,层次; 等级制度; 统治集团; 天使的级别或等级; inheritance n. 继承 ...
- Linux 上安装 Node.js
Linux 上安装 Node.js 直接使用已编译好的包(在个人阿里云服务器47.100.6.106上安装) Node 官网已经把 linux 下载版本更改为已编译好的版本了,我们可以直接下载解压后使 ...