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 ...
随机推荐
- Applications using Launch Screen Files and targetting iOS 7.1 and earlier need to also include a Launch Image in an Asset Catalog.
在使用xcode6建的项目时,有时在ios7模拟器下会出现一下情况 导航栏上方和tabbar下方会有黑边 并且会有一下警告: Applications using Launch Screen File ...
- 洛谷 P3960 [ NOIP 2017 ] 列队 —— 线段树
题目:https://www.luogu.org/problemnew/show/P3960 NOIP 题,不用很复杂的数据结构...但又参考了许多: 要求支持维护删除第 k 个和在末尾插入的数据结构 ...
- uva10828
https://vjudge.net/problem/UVA-10828 裸高斯消元... 但是要判无解和无穷解. 当出现一个环时会无解,环上每个点只有一个出边. #include<bits/s ...
- 乐搏讲自动化测试-Python发展背景(1)
相信小伙伴们都知道,随着软件测试行业的发展和进步自动化测试已经成为必然.在竞争日益激烈的市场环境中也是你升职加薪的利器. 所以,小编决定从今天起!将要系统.连续.高质量的持续更新「整套自动化测试」文章 ...
- 前端javascript 错误 Uncaught SyntaxError: Unexpected token ILLEGAL
前端控制台报Uncaught SyntaxError: Unexpected token ILLEGAL 错误时,就是非法字符错误,首先检查符号是否正确,不要出现中文标点! 然后检查参数之类的类型是否 ...
- BFS(两点搜索) FZOJ 2150 Fire Game
题目传送门 题意:'#'表示草地,两个人在草地上点火,相邻的草地会烧起来,每烧一格等1秒,问最少要等几秒草地才烧完 分析:这题和UVA 11624 Fire!有点像,那题给定了两个点,这题两点不确定, ...
- 数学+DP Codeforces Round #304 (Div. 2) D. Soldier and Number Game
题目传送门 /* 题意:这题就是求b+1到a的因子个数和. 数学+DP:a[i]保存i的最小因子,dp[i] = dp[i/a[i]] +1;再来一个前缀和 */ /***************** ...
- 转 awr自动收集脚本
1. remote get awr report #!/usr/bin/ksh ####sample: sh awr.sh 20170515 20170516 AWR ### default it w ...
- pip安装itchat模块成功后annocanda中No module named 'itchat'
在cmd中pip install itchat 成功后在annocanda中却出现了下面的情况: 经过查找网上各种查询,原来pip默认是把东西安装在系统python环境中,即C:\Python27\L ...
- 四种IO模型
四种 IO 模型: 首先需要明确,IO发生在 用户进程 与 操作系统 之间.可以是客户端IO也可以是服务器端IO. 阻塞IO(blocking IO): 在linux中,默认情况下 ...