python 刷博客访问量脚本

时间:2021-10-11 00:11:12

通过页面源码找到增加访问量的url

http://blog.51cto.com/js/header.php?uid=822334&tid=xxxx

通过python脚本访问

 

  
 
 
  1. import urllib2 
  2. import re 
  3. import sys 
  4. import time 
  5. import threading 
  6. l=[] 
  7. def main(): 
  8.     list1=[] 
  9.     list2=[] 
  10.     global l 
  11.     pr=r'<a href="/822334/(\d+)' 
  12.     rr=re.compile(pr) 
  13.     yeurl=['http://gaoming.blog.51cto.com/all/822334/page/1','http://gaoming.blog.51cto.com/all/822334/page/2','http://gaoming.blog.51cto.com/all/822334/page/3'
  14.     for i in yeurl: 
  15.         req=urllib2.Request(i) 
  16.         req.add_header("User-Agent","Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)"
  17.         cn=urllib2.urlopen(req) 
  18.         f=cn.read() 
  19.         list2=re.findall(rr,f) 
  20.         list1=list1+list2 
  21.         cn.close() 
  22.     for o in list1: 
  23.         url='http://blog.51cto.com/js/header.php?uid=822334&tid='+o 
  24.         l.append(url) 
  25. def su(url): 
  26.     c=urllib2.urlopen(url) 
  27.     print c.read() 
  28.     c.close() 
  29.     time.sleep(10
  30.     sem.release()                           
  31. if __name__ == "__main__"
  32.     main() 
  33.     maxThread=5 
  34.     sem=threading.BoundedSemaphore(maxThread)      
  35.     while 1:         
  36.         for i in l: 
  37.             sem.acquire() 
  38.             T=threading.Thread(target=su,args=(i,)) 
  39.             T.start() 

纯属无聊之作

本文出自 “高明” 博客,请务必保留此出处http://gaoming.blog.51cto.com/822334/1195390