协程+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')
])
标签:spawn,f1,www,协程,https,url,小爬虫,gevent,IO 来源: https://www.cnblogs.com/xuyuwei/p/11550295.html