爬虫爬取文字生成词云

import requests
import re
import wordcloud
import imageio
import jieba
response = requests.get('http://www.haha56.net/xiaohua/gushi/list_1_2.html')
response.encoding='gbk'
data = response.text
data_result = re.findall('

(.*?)
',data)
data_result_str = ''.join(data_result)
w = wordcloud.WordCloud(font_path=r'C:\Windows\Fonts\微软雅黑\msyhbd') ##选择字体
w.generate(data_result_str)
w.to_file('outfile.png') ##输出png

posted @ 2019-07-22 19:18  oxtime  阅读(730)  评论(0编辑  收藏  举报