码迷,mamicode.com
首页 > 编程语言 > 详细

python实现模拟浏览器訪问网页

时间:2017-06-19 12:58:25      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:int   star   实现   pos   name   log   etc   request   time   

原文:http://blog.csdn.net/boksic/article/details/16870453

import urllib2  
import timeit  
import thread   
import time  
i = 0  
x = 0
mylock = thread.allocate_lock()  
def test(no,r):  
    global i  
    url = ‘http://blog.csdn.net/‘  
    for j in range(1,r):  
        req=urllib2.Request(url)   
        req.add_header("User-Agent","Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)")   
        file = urllib2.urlopen(req)  
        print file.getcode();  
        mylock.acquire()  
        i+=1  
        mylock.release()      
        print i;  
        thread.exit_thread()  
def fast():  
		thread.start_new_thread(test,(1,50))  
		thread.start_new_thread(test,(2,50))   
		thread.start_new_thread(test,(3,50)) 
		thread.start_new_thread(test,(4,50)) 
		thread.start_new_thread(test,(5,50))
		thread.start_new_thread(test,(6,50))
		thread.start_new_thread(test,(7,50))
for x in range(1,150): 
	fast()  
	time.sleep(0.08)  
	x = x + 1


python实现模拟浏览器訪问网页

标签:int   star   实现   pos   name   log   etc   request   time   

原文地址:http://www.cnblogs.com/jzdwajue/p/7047770.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!