本文主要是介绍玩转Python :获取微信好友个性签名生成词云,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
运行结果:
需要用到的库itchat、matplotlib、re、wordcloud、jieba。
import itchat
import re
import jieba
import matplotlib.pyplot as plt
from wordcloud import WordClouditchat.auto_login(True)
friends = itchat.get_friends(update=True)[0:]
tList = []
for i in friends:signature = i["Signature"].replace(" ", "").replace("span", "").replace("class", "").replace("emoji", "")rep = re.compile("< =.+/>")signature = rep.sub("", signature)tList.append(signature)# 拼接字符串
text = "".join(tList)# jieba分词
wordlist_jieba = jieba.cut(text, cut_all=True)
wl_space_split = " ".join(wordlist_jieba)# #如果是中文必须要添加字体路径,否则会显示成框框
my_wordcloud = WordCloud(background_color="white", width=1600, height=1200,font_path='C:\Windows\Fonts\msyh.ttc').generate(wl_space_split)plt.imshow(my_wordcloud)
plt.axis("off")
plt.show()
运行过程:
这篇关于玩转Python :获取微信好友个性签名生成词云的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!