17年春节各语言程序员努力指数
新年第一天上班,学习了python,自定一个题目查看过年期间,各种语言程序员发表博客情况,看下程序员的努力情况,具体办法是抓取cnblogs中各个博客发表日期,查看放假期间方标数量对比下,纯属娱乐,如有不适,敬请谅解,呵呵!
import re import urllib2 import datetime def getHtml(url): res = urllib2.urlopen(url) html = res.read() return html def getcount(html): t_str = '2017-02-03 00:00:01' restr = r'发布于\s\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}' dd = re.compile(restr) dl = re.findall(dd,html) now = datetime.datetime.strptime(t_str,'%Y-%m-%d %H:%M:%S') i = 0 for date in dl: dreg = r'\d{4}-\d{2}-\d{2}' ddreg = re.compile(dreg) dateres = re.findall(ddreg,date) dte = dateres[0] a=datetime.datetime.strptime(dte,"%Y-%m-%d") delta = now - a if delta.days < 10 and delta.days >0:
i = i+1 return i def getAllcount(lan): url = "http://www.cnblogs.com/cate/" + lan + "/" count = 0 a = True page = 1 while a: uurl = url + str(page) cnt =getcount(getHtml(uurl)) count = count + cnt if cnt == 20: page = page + 1 else: a = False return count lanlist = ["108698","cpp","java","php","delphi","python","ruby","c","erlang","go","swift","scala","r","verilog","otherlang""108703"]
for l in lanlist: print getAllcount(l)
这是全部代码,结果
.net:17
cpp:19
java:33
php:3
delphi:0
python:10
ruby:0
c:8
erlang:1
go:0
swift:0
scala:2
r:0
verilog:0
web前端:19
otherlang:1
做个图,今年争取发表个论文,练练制图:
不考虑总量的情况下,还是java程序员工作努力啊,web前端和c++次之,python也不错。。。