周末了,八一八推荐博客的排名

news/2024/7/19 12:00:28 标签: 爬虫, python, json

作者: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 cnblogs

import requests
import BeautifulSoup

import re
import json
from datetime import datetime

def 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 page

def 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 info

def 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 info

if __name__ == "__main__":
    info = cnblogs_recommend_150()

 

Javascript代码所在位置。

 

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


http://www.niftyadmin.cn/n/806773.html

相关文章

我看程序员 (转)

我看程序员 (转)[more]朋友请我写篇文章,谈谈如何编程。我非功成名就之高人,自己那点儿经验拿出来会被人笑话的。但是看到周围很多师弟师妹正在走我以前走过的错路,使我不得不斗胆说几句,只望大家在程序员的道路上一帆风顺就好。 …

javaScript知识点回顾(三十四):文档对象模型(DOM)

1)DOM的官方定义 DOM , Document Object Model ,文档对象模型。我们可以把网页中的所有“东西”看成是“对象”。DOM是W3C制定的网页标准或规则,而这个标准,在浏览器中,以“对象”的形式得以实现。DOM的官方…

MySQL-3-DML语言

1、外键 (1)外键概念 如果公共关键字在一个关系中是主关键字,那么这个公共关键字被称为另一个关系的外键。由此可见,外键表示了两个关系之间的相关联系。以另一个关系的外键作主关键字的表被称为主表,具有此外键的表被…

关于MySQL的only_full_group_by的err的矫正

最近mysql数据库版本5.7执行SQL语句的时候,出现错[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column ‘information_schema.PROFILING.SEQ’ which is not functionally dependent on columns in GROUP …

有关COM的一些基本知识 (转)

有关COM的一些基本知识 (转)[more]组件对象模型的基本知识 基于构件的软件开发日益流行,这里我吧自己在学校时整理的关于COM的一些东西献给大家,供初学者参考.一.组件(COM),是微软公司为了计算机工业的软件生产更加符合人类的行…

idea关联mysql报出不成功:Server returns invalid timezone. Go to ‘Advanced‘ tab and set ‘serverTimezone‘ pro

这个属于时区问题 原因是MySQL默认的时区是UTC时区,比北京时间晚8个小时。 所以要进行如下设置 如图 进入dos命令窗口后,首先输入: mysql -uroot -p 回车:屏幕提示输入你的数据库连接密码 :如 123456 然后输入&#xf…

了不起的 Creator Shader 修仙之路—相册转场特效

相册是一个大家比较熟悉的场景,一般我们是实现的都是那种跑马灯式的轮播相册,这里异名给大家提供一个利用shader实现图片渐变过渡的相册思路demo实现思路拆分一下功能点,主要有两个:一个是实现图片的渐变,一个是实现图…

高效获取网页源码COM

目前获取网页源码有几种方法: 1、WebClient下载页面2、HttpWebRequest发请求获取3、com组件xmlhttp获取 三者比较:WebClient代码最少,效率最慢;xmlhttp代码适中,效率最高,效率和前两者比较不是一个级别的&a…