• 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 import threading
     9 mylock = threading.RLock()  
    10 
    11 tabcount=1
    12 
    13 def BlogFun(n,url,MaxVisitor,threadnumber):
    14     visitcount = r'<span class="link_view" title="阅读次数">(d+)人阅读</span>'
    15     global tabcount 
    16     while True:
    17         mylock.acquire()  
    18         if tabcount >10:
    19             os.system('taskkill /F /IM chrome.exe')
    20             tabcount = 1
    21         else:
    22             tabcount = tabcount + 1
    23         mylock.release()  
    24         webbrowser.open(url,new=1)
    25         request=urllib2.Request(url)
    26         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')
    27         opener = urllib2.build_opener()
    28         fblog = opener.open(request)
    29         htm = fblog.read()
    30         Ref=re.findall(visitcount,htm)
    31         time.sleep(n)
    32         if int(Ref[0])>MaxVisitor:
    33             break
    34        
    35 
    36 
    37 if __name__=="__main__":
    38 
    39     main_url = "http://blog.csdn.net/u013018721/article/details/37996979"
    40    
    41     threadSum= 5
    42     MaxVisitor = 1050
    43     timedelay=3
    44     print main_url+" 开启模式... "+"
    "
    45     for threadnumber in range(threadSum):
    46         thread.start_new_thread(BlogFun,(timedelay,main_url,MaxVisitor,threadnumber,))
    47         threadnumber=threadnumber+1
    48     
    49     print "Main Thread Over.............."
  • 相关阅读:
    load data to matlab
    Apriori algorithm
    LOGIN Dialogue of Qt
    Methods for outlier detection
    MFC改变对话框背景色
    g++宏扩展
    Some key terms of Data Mining
    Qt QLabel 显示中文
    How To Debug a Pyhon Program
    C++命名规范
  • 原文地址:https://www.cnblogs.com/vpoet/p/4659563.html
Copyright © 2020-2023  润新知