一个python爬虫协程的写法(gevent模块)
2017-09-05 15:35
537 查看
from bs4 import BeautifulSoup import requests import gevent from gevent import monkey, pool monkey.patch_all() jobs = [] links = [] p = pool.Pool(10) urls = [ 'http://www.google.com', # ... another 100 urls ] def get_links(url): r = requests.get(url) if r.status_code == 200: soup = BeautifulSoup(r.text) links + soup.find_all('a') for url in urls: jobs.append(p.spawn(get_links, url)) gevent.joinall(jobs)
相关文章推荐
- 详解python之协程gevent模块
- python采用 多进程/多线程/协程 写爬虫以及性能对比,牛逼的分分钟就将一个网站爬下来!
- python模块介绍-gevent介绍:基于协程的网络库
- ubuntu下安装python的gevent模块遇到的一个问题
- python中的协程模块gevent
- 第三百五十节,Python分布式爬虫打造搜索引擎Scrapy精讲—selenium模块是一个python操作浏览器软件的一个模块,可以实现js动态网页请求
- [Python]网络爬虫(六):一个简单的百度贴吧的小爬虫 Python 3.6 改写
- 利用Flask + python3.6+MYSQL编写一个简单的评论模块。
- 使用Python编写爬虫的基本模块及框架使用指南
- python logging 模块之TimedRotatingFileHandler 实现每天一个日志文件
- Python写的一个爬虫程序
- 一个用Python实现的多入口全网爬的多线程爬虫的实现
- python简单爬虫(上):urllib,urllib2与cookielib三个模块
- 毕业设计中怎样用python写一个搜索引擎的分布式爬虫---异样的美感
- 一个简单的多线程Python爬虫
- python脚本初探---新手如何直接编写一个hello world模块即可执行的.py文件
- python实例1:创建一个登陆模块
- Python 网络爬虫 002 (入门) 爬取一个网站之前,要了解的知识
- Python爬虫----网页下载器和urllib2模块及对应的实例
- 一个简单的 python3 爬虫