时间: 2020-09-2|31次围观|0 条评论

作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明。谢谢!

 

最近挖煤君上了博客园推荐博客的排行榜,甚是高兴。看着自己名次上升,是件很开心的事情。

看着推荐榜上的诸位大神,再加上QQ群里的交流,我骨子里的八卦精神又一次发痒,所以就做了个爬虫,把推荐榜上各位的入园时间、粉丝数、排名给搜罗了一下,做成一个泡泡图。

 

看起来,排名不是完全由粉丝数决定的,但也有相当大的相关性。大伙的眼睛是雪亮的啊。

看到肥嘟嘟沉淀在下面的诸位大神,挖煤君表示由衷敬佩。

大家来找自己的泡泡吧。Vamei躲在右下角的小角落哦!

 

挖煤君的小小爬虫是Python写的,图是D3.js画的。欢迎点赞留言加粉儿哦,挖煤君也想向下沉淀沉淀。

 

泡泡的面积和粉丝数成正比,x轴为入园时间,y轴为排名。

D3老的浏览器可能不支持。Chrome效果最佳。各位能给我反馈一下不同浏览器的效果如何?

2014.03.08数据更新

 

Python爬虫代码:

#-*- coding: UTF-8 -*-# By Vamei# scrape the cnblogsimport requestsimport BeautifulSoupimport reimport jsonfrom datetime import datetimedef read_page(url, method="get"):    '''    read the html page via the URL    '''    status_code = 0    while status_code != 200:        if method == "get":            r = requests.get(url)        elif method == "post":            r = requests.post(url)        status_code = r.status_code        print status_code    page = r.content    return pagedef parse_person_profile(relative, info={}):    '''    retrieve the information from the personal profile page    '''    r = read_page("http://home.cnblogs.com/u%s" % relative)    soup  = BeautifulSoup.BeautifulSoup(r)    # the count of the followers    el            = soup.find("a", {'id':"follower_count"})    info['粉丝数']   =  int(el.getText())    # the time of the registration    el       = soup.find("div", {'id': "ctl00_cphMain_panel_profile"})    profile  =  el.ul    reg_time =  el.ul.findChildren()[0]    raw = reg_time.getText()    m   = re.findall("(\d+)", raw)    m   =  map(int, m)    dt  = datetime(year=m[0], month=m[1], day=m[2])    info['开博时间'] = dt.strftime("%Y%m%d")    return infodef cnblogs_recommend_150():    '''    workhouse    '''    url = "http://www.cnblogs.com/aggsite/ExpertBlogs"    r = read_page(url, method="post")    soup = BeautifulSoup.BeautifulSoup(r)    # retrieve the information blogger by blogger    info = []    anchors = soup.findAll('a')    # blogger by blogger    for i, a in enumerate(anchors):        name = a.getText()        p_info = {'昵称': name, '排名': i + 1}        # parse_person_main(a['href'], p_info)        parse_person_profile(a['href'], p_info)        info.append(p_info)    # write the retrieved data into the file    with open("info", "w") as f:        rlt = json.dumps(info, indent=4, encoding="UTF-8", ensure_ascii=False)        f.write(rlt.encode("utf8"))    return infoif __name__ == "__main__":    info = cnblogs_recommend_150()

 

Javascript代码所在位置

 

文章转载于:https://www.cnblogs.com/vamei/p/3583398.html

原著是一个有趣的人,若有侵权,请通知删除

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《周末了,八一八推荐博客的排名
   

还没有人抢沙发呢~