python刷取CSDN博文访问量之三
2015-06-28 21:41
411 查看
python刷取CSDN博文访问量之三
作者:vpoet
注:这个系列我只贴代码,代码不注释.有兴趣的自己读读就懂了,纯属娱乐,望管理员抬手
若有转载一定不要注明来源
作者:vpoet
注:这个系列我只贴代码,代码不注释.有兴趣的自己读读就懂了,纯属娱乐,望管理员抬手
若有转载一定不要注明来源
#coding=utf-8 import webbrowser import time import urllib2 import re import os import thread import threading mylock = threading.RLock() tabcount=1 def BlogFun(n,url,MaxVisitor): visitcount = r'<span class="link_view" title="阅读次数">(\d+)人阅读</span>' global tabcount while True: mylock.acquire() if tabcount >10: os.system('taskkill /F /IM chrome.exe') tabcount = 1 else: tabcount = tabcount + 1 mylock.release() webbrowser.open(url,new=1) request=urllib2.Request(url) 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') opener = urllib2.build_opener() fblog = opener.open(request) htm = fblog.read() Ref=re.findall(visitcount,htm); #print url+": "+str(int(Ref[0]))+"人阅读" if int(Ref[0])>MaxVisitor: break time.sleep(n) if __name__=="__main__": Domain="http://blog.csdn.net" main_url = "http://blog.csdn.net/u013018721" patt_article = r'<span class="link_title"><a href="(.+)">' Mainrequest=urllib2.Request(main_url) Mainrequest.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') opener = urllib2.build_opener() fMainblog = opener.open(Mainrequest) Mainhtml= fMainblog.read() article_urls = re.findall(patt_article,Mainhtml) threadnumber = 1 MaxVisitor = 300 timedelay=3 for item in article_urls: Realurl = Domain+item thread.start_new_thread(BlogFun,(timedelay,Realurl,MaxVisitor,)) threadnumber=threadnumber+1
相关文章推荐
- python刷取CSDN博文访问量之二
- python刷取CSDN博文访问量之一
- Python源码剖析笔记3-Python执行原理初探
- Python requests 自动登录某财BBS,自动签到打卡领铜钱,最后再配个plist,每天自动执行
- 用python获取MAC地址和IP地址
- python中的面向对象编程
- Python学习笔记 - function调用和定义
- Python学习笔记 - function调用和定义
- win python3.4.3安装和环境变量配置
- Python学习笔记 - dict和set
- Python学习笔记 - dict和set
- maya-python-pyqt-delete-all-widgets-in-a-layout/
- Python学习笔记 - ifelifelse-forin-while
- Python学习笔记 - ifelifelse-forin-while
- 隔离python环境的virtualenv
- Mac OS安装IPython
- Python 列表(List)操作方法详解
- 举例详解Python中的split()函数的使用方法
- python写日志封装类实例
- Python学习笔记 - list和tuple