今天一时兴起,想用python爬爬自己的博客,通过数据聚合,制作高逼格的云图(对词汇出现频率视觉上的展示),看看最近我到底写了啥文章。
一、直接上几张我的博客数据的云图
1.1 爬取文章的标题的聚合



1.2 爬取文章的摘要的聚合


1.3 爬取文章的标题+摘要的聚合


我最近写了SpringCloud系列教程,还有一些微服务架构方面,从云图上看,基本吻合。你若不信,可以进我的博客看看,数据还是非常准确的
二、技术栈
- 开发工具: pycharm
- 爬虫技术:bs64、requsts、jieba
- 分析工具:wordArt
三、爬虫构架设计

整个爬虫架构非常简单:
- 爬取我的博客:http://blog.csdn.net/forezp
- 获取数据
- 将数据用“结巴”库,分词。
- 将得到的数据在在artword上制作云图。
- 将制作出来的云图展示给用户。
四、具体实现
先根据博客地址爬去数据:
url = 'http://blog.csdn.net/forezp'
titles=set()
def download(url):
if url is None:
return None
try:
response = requests.get(url, headers={
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36',
})
if (response.status_code == 200):
return response.content
return None
except:
return None
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
解析标题
def parse_title(html):
if html is None:
return None
soup = BeautifulSoup(html, "html.parser")
links = soup.find_all('a', href=re.compile(r'/forezp/article/details'))
for link in links:
titles.add(link.get_text())
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
解析摘要:
def parse_descrtion(html):
if html is None:
return None
soup=BeautifulSoup(html, "html.parser")
disciptions=soup.find_all('div',attrs={'class': 'article_description'})
for link in disciptions:
titles.add(link.get_text())
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
用“结巴”分词,”激8”分词怎么用,看这里:https://github.com/fxsjy/jieba/
def jiebaSet():
strs=''
if titles.__len__()==0:
return
for item in titles:
strs=strs+item;
tags = jieba.analyse.extract_tags(strs, topK=100, withWeight=True)
for item in tags:
print(item[0] + '\t' + str(int(item[1] * 1000)))
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
因为数据比较少,所以我直接打印在控制台,并把它复制下来,更好的方法是存在mongodb中。
制作云图:
用 artword在线工具,地址:https://wordart.com
首先:
导入从控制台复制过来的数据:

令人尴尬的是,这个网站在绘制图的时候不支持中文,需要你从c:/windows/fonts下选择一个支持中文的字体,mac 用户从windows拷下文件夹也可以,或者在网上下。

然后点击Visulize就可以生成高逼格的云图了。讲解完毕,有什么需要改进的请大家留言。
源码下载:https://github.com/forezp/ZhihuSpiderMan/tree/master/blogspider
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步