python云图制作壮观天体照_Python爬取个人博客,带你制作高逼格的数据聚合云图...

点击上方“中兴开发者社区”,关注我们

每天读一篇一线开发者原创好文

本文出自方志朋的博客

链接:http://blog.csdn.net/forezp/article/details/70198541

一时兴起,想用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

解析标题

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())

解析摘要:

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())

用“结巴”分词,”激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)))

因为数据比较少,所以我直接打印在控制台,并把它复制下来,更好的方法是存在MongoDB中。

制作云图:

用 artword在线工具,地址:https://wordart.com

首先:

导入从控制台复制过来的数据:

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

然后点击Visulize就可以生成高逼格的云图了。讲解完毕,有什么需要改进的请大家留言。

源码下载:

https://github.com/forezp/ZhihuSpiderMan/tree/master/blogspider

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值