词云绘制
第三方库 wordcloud pip install wordcloud 指定镜像源: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple wordcloud 文档:https://amueller.github.io/word_cloud/index.html wordcloud.WordCloud() 案例 1:”政府工作报告爬取与词云绘制“ python 1 2 3 4 5 6 7 8 9 10 11 12 13 import urllib.request from bs4 import BeautifulSoup from wordcloud import WordCloud url = "https://www.gov.cn/zhuanti/2021lhzfgzbg/index.htm" response = urllib.request.urlopen(url) html = response.read().decode("utf-8") soup = BeautifulSoup(html, "html.parser") content = soup.find("div", class_="zhj-bbqw-cont").text w = WordCloud(font_path="/Fonts/simhei.ttf").generate(content) w.to_file("政府工作报告y1.png") ...