首先,在QQ的消息管理器中将某一个人或者全部的聊天记录导出成txt格式,放入F盘下;
运行下面的python代码需要安装jieba和wordcloud两个库。
import matplotlib.pyplot as plt
from wordcloud import WordCloud
import jieba
from wordcloud import WordCloud, ImageColorGenerator
import os
import numpy as np
import PIL.Image as Image
newtext = []
#打开F盘下的聊天记录文件e.txt
for word in open('F:\\e.txt', 'r',encoding='utf-8'):
tmp = word[0:4]
#print(tmp)
if (tmp == "2017" or tmp == "===="):#过滤掉聊天记录的时间和qq名称
continue
tmp = word[0:2]
#print(tmp)
if (tmp[0] == '[' or tmp[0] == '/'):#过滤掉图片和表情,例如[图片],/可爱
continue
newtext.append(word)
#将过滤掉图片和表情和时间信息和qq名称剩下的文字重新写入F盘下的ab.txt文件中去
with open('F:\\a2.txt', 'w', encoding='utf-8') as f:
for i in newtext: