Python3之协程爬虫应用
2017-08-31 17:10
253 查看
from gevent import monkey; monkey.patch_all() import gevent, requests def get_page(url): ret = requests.get(url).text with open('b.txt', 'a', encoding='utf-8') as f: f.write('%s-%s\n' % (url, len(ret))) # g1 = gevent.spawn(get_page, 'http://www.openstack.org') g2 = gevent.spawn(get_page, 'https://www.python.org') g3 = gevent.spawn(get_page, 'http://www.sina.com.cn/') gevent.joinall([g2, g3])
所用时间是网络延迟最长还有写文件最耗时的那个任务的时间!!!
相关文章推荐
- python 多线程、多进程、协程性能对比(以爬虫为例)
- 【Python实战】Scrapy豌豆荚应用市场爬虫
- Python实现基于协程的异步爬虫
- Python简单爬虫的应用
- Python协程并发 爬虫下载
- Python爬虫-scrapy框架简单应用
- Python爬虫包 BeautifulSoup 学习(八) parent等应用
- python协程及应用(一):简介
- 精通Python爬虫从Scrapy到移动应用(文末福利)
- Python实现基于协程的异步爬虫(一)
- Python实现基于协程的异步爬虫
- Python 爬虫小程序(正则表达式的应用)
- python协程及应用(一):简介
- python网络应用入门:网络爬虫的使用
- python采用 多进程/多线程/协程 写爬虫以及性能对比,牛逼的分分钟就将一个网站爬下来!
- 深入理解Python中协程的应用机制: 使用纯Python来实现一个操作系统吧!!
- Python爬虫包 BeautifulSoup 学习(七) children等应用
- re正则在python爬虫的应用
- Python 协程并发爬虫网页