python刷取CSDN博文访问量之一

python刷取CSDN博文访问量之一
作者:vpoet
注:这个系列我只贴代码,代码不注释.有兴趣的自己读读就懂了,纯属娱乐,望管理员抬手
若有转载一定不要注明来源
 
 1 #coding=utf-8
 2 import webbrowser
 3 import time
 4 import urllib2
 5 import re
 6 import os
 7 import thread
 8 
 9 
10 tabcount=1
11 
12 def BlogFun(n,url,MaxVisitor):
13     visitcount = r'<span class="link_view" title="阅读次数">(d+)人阅读</span>'
14     global tabcount 
15     while True:
16         if tabcount >10:
17             os.system('taskkill /F /IM chrome.exe')
18             tabcount = 1
19         else:
20             tabcount = tabcount + 1
21         webbrowser.open(url,new=1)
22         request=urllib2.Request(url)
23         request.add_header('User-Agent','Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6')
24         opener = urllib2.build_opener()
25         fblog = opener.open(request)
26         htm = fblog.read()
27         Ref=re.findall(visitcount,htm);
28         print url+": "+str(int(Ref[0]))+"人阅读"
29         if int(Ref[0])>MaxVisitor:
30             break
31         time.sleep(n)
32 
33 
34 if __name__=="__main__":
35 
36     
37     Domain="http://blog.csdn.net"
38     Blog_url = "http://blog.csdn.net/u013018721/article/details/37996979"
39     FreshSecond = 3
40     MaxVisitor = 1000
41     BlogFun(FreshSecond,Blog_url,MaxVisitor)
原文地址:https://www.cnblogs.com/vpoet/p/4659564.html