zoukankan      html  css  js  c++  java
  • 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.............."
  • 相关阅读:
    Linux yum命令重装mysql
    Java多线程编程<一>
    Java内存区域与内存溢出异常
    实现一个线程安全的Queue队列
    Java 原始数据类型转换
    对象-关系映射ORM(Object Relational Mapping)(转)
    2进制,16进制,BCD,ascii,序列化对象相互转换
    Apache MINA 框架之默认session管理类实现
    Struts.properties(转)
    vue常用插件-数字滚动效果vue-count-to
  • 原文地址:https://www.cnblogs.com/vpoet/p/4659563.html
Copyright © 2011-2022 走看看