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 爬取微信好友列表和个性签名,绘制个性签名云图的更多相关文章

  1. 我用 Python 爬取微信好友,最后发现一个大秘密

    前言 你身处的环境是什么样,你就会成为什么样的人.现在人们日常生活基本上离不开微信,但微信不单单是一个即时通讯软件,微信更像是虚拟的现实世界.你所处的朋友圈是怎么样,慢慢你的思想也会变的怎么样.最近在 ...

  2. Python爬取微信好友

    前言 今天看到一篇好玩的文章,可以实现微信的内容爬取和聊天机器人的制作,所以尝试着实现一遍,本文记录了实现过程和一些探索的内容 来源: 痴海 链接: https://mp.weixin.qq.com/ ...

  3. python itchat 爬取微信好友信息

    原文链接:https://mp.weixin.qq.com/s/4EXgR4GkriTnAzVxluJxmg 「itchat」一个开源的微信个人接口,今天我们就用itchat爬取微信好友信息,无图言虚 ...

  4. Python3 爬取微信好友基本信息,并进行数据清洗

    Python3 爬取微信好友基本信息,并进行数据清洗 1,登录获取好友基础信息: 好友的获取方法为get_friends,将会返回完整的好友列表. 其中每个好友为一个字典 列表的第一项为本人的账号信息 ...

  5. python爬取微信小程序(实战篇)

    python爬取微信小程序(实战篇) 本文链接:https://blog.csdn.net/HeyShHeyou/article/details/90452656 展开 一.背景介绍 近期有需求需要抓 ...

  6. Python爬取微信小程序(Charles)

    Python爬取微信小程序(Charles) 本文链接:https://blog.csdn.net/HeyShHeyou/article/details/90045204 一.前言 最近需要获取微信小 ...

  7. python爬取微信公众号

    爬取策略 1.需要安装python selenium模块包,通过selenium中的webdriver驱动浏览器获取Cookie的方法.来达到登录的效果 pip3 install selenium c ...

  8. Python:爬取乌云厂商列表,使用BeautifulSoup解析

    在SSS论坛看到有人写的Python爬取乌云厂商,想练一下手,就照着重新写了一遍 原帖:http://bbs.sssie.com/thread-965-1-1.html #coding:utf- im ...

  9. 使用Python爬取微信公众号文章并保存为PDF文件(解决图片不显示的问题)

    前言 第一次写博客,主要内容是爬取微信公众号的文章,将文章以PDF格式保存在本地. 爬取微信公众号文章(使用wechatsogou) 1.安装 pip install wechatsogou --up ...

随机推荐

  1. 蓝桥 ADV-232 算法提高 矩阵乘法 【区间DP】

      算法提高 矩阵乘法   时间限制:3.0s   内存限制:256.0MB      问题描述 有n个矩阵,大小分别为a0*a1, a1*a2, a2*a3, ..., a[n-1]*a[n],现要 ...

  2. SQL SERVER 安装软件 及导入项目流程

    1.安装sqlsever2000及以上 数据库 (在百度上找安装文档) 创建账户 密码 2.解压SQL2000-KB884525-SP4-x86-CHS.EXE补丁 之后安装补丁 ,在安装补丁是会用到 ...

  3. BZOJ_1493_[NOI2007]项链工厂_Splay

    BZOJ_1493_[NOI2007]项链工厂_Splay Description T公司是一家专门生产彩色珠子项链的公司,其生产的项链设计新颖.款式多样.价格适中,广受青年人的喜爱. 最近T公司打算 ...

  4. bzoj2763 [JLOI2011]飞行路线——分层图

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 构建分层图. 代码如下: 写法1(空间略大)(时间很慢): #include<i ...

  5. Python基础第二天

    一.内容 二.练习 练习1 题目:已知msg='hello knight 666'编写for循环,利用索引遍历出每一个字符 图示: 代码: msg = 'hello knight 666' msg_l ...

  6. easyui 生成tas方式

    1.采用<a>标签形式 <div id="tabs" style="width:100%;"> <ul> <li id ...

  7. httpd 安装ssl证书

    1) 安装ssl模块 # yum install mod_ssl -y Ps:安装完成后,会在/etc/httpd/conf.d/下生成一个ssl.conf配置文件. 2) 先建一个目录用来放ssl证 ...

  8. Linux学习之路2 Bash的基本操作

    一.SHELL的介绍 shell分为两种:CLI(command Line Interface)和GUI(Graphical User Interface) 操作系统中的shell: GUI:GNOM ...

  9. FJOI2019退役记

    day1 不意外地一点都不紧张,早就感觉没有机会了吧 进场非常从容地读完了三道题,开始写t1暴力,接着就开始自闭,不知道该开t2还是t3,最后先开了t3,想了想这不是选两条不相交的链吗,这个暴力不是林 ...

  10. EditText(6)EditText的子类

      1.Known Direct Subclasses AppCompatEditText, AutoCompleteTextView, ExtractEditText, GuidedActionEd ...