协程+IO切换+小爬虫

from gevent import monkey
monkey.patch_all()

import gevent
import requests


def f1(url):
print(f'GET:{url}')
msg = requests.get(url)
  # 获取的是网站的数据长度
print(len(msg.content))


gevent.joinall([
gevent.spawn(f1, 'https://www.python.org'),
gevent.spawn(f1, 'https://www.github.com'),
gevent.spawn(f1, 'https://www.yahoo.com')
])
posted @ 2019-09-19 15:55  徐-  阅读(169)  评论(0编辑  收藏  举报