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

Python爬虫

时间:2016-12-22 20:25:26      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:.com   art   http   pre   cost   nal   log   test   span   

#Author:xuesong li

import gevent
from gevent import monkey
monkey.patch_all()
from  urllib.request import urlopen
import time

def pa_web_page(url):
    print("GET url",url)
    req = urlopen(url)
    data =req.read()
    print(data)
    f = open("test",‘w‘)
    f.read(data)
    f.close()
   

    print(%d bytes received from %s. % (len(data), url))

t_start = time.time()
pa_web_page("http://www.autohome.com.cn/beijing/")
pa_web_page("http://www.xiaohuar.com/")
print("time cost:",time.time()-t_start)



t2_start = time.time()
gevent.joinall([
        #gevent.spawn(pa_web_page, ‘https://www.python.org/‘),
        gevent.spawn(pa_web_page, http://www.autohome.com.cn/beijing/),
        gevent.spawn(pa_web_page, http://www.xiaohuar.com/),
        #gevent.spawn(pa_web_page, ‘https://github.com/‘),
])
print("time cost t2:",time.time()-t2_start)

 

Python爬虫

标签:.com   art   http   pre   cost   nal   log   test   span   

原文地址:http://www.cnblogs.com/lixuesong/p/6212352.html

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