python-爬网页

import gevent
from urllib.request import urlopen


# 爬虫
def f(url):
print('GET: %s' % url)
resp = urlopen(url)
data = resp.read()

with open('baidu.html', 'wb') as f:
f.write(data)

print('%d bytes %s' % (len(data), url))


# f('http://www.xiaohuar.com/')
f('http://www.baidu.com/')


# gevent.joinall([
#
# gevent.spawn(f, 'https://www.python.org/'),
# gevent.spawn(f, 'https://www.yahoo.com/'),
#
# ])
posted @ 2017-12-14 19:26  巅峰之斗  阅读(382)  评论(0编辑  收藏  举报