考虑到垂直爬虫及站内搜索的重要性,重新思考一下项目爬虫的技术架构及实现方案。以前的垂直爬虫曾经使用过heritrix、htmlparser、nutch等,各有优缺点。尤其是要做垂直网站的定向爬取时候,并没有太好的方案,只能够做指定页面的定向解析,因此以前主要还是使用htmlparser的方案。
考察垂直爬虫的几个原则:
- 性能较高:较好支持多线程并发处理;支持异步、非阻塞socket;支持分布式爬取;爬取调度算法性能较高;内存使用效率较高,不要老是出现out of memory问题;
- 架构优美:组件式设计式架构,扩展方便;架构设计精巧。至少值得花时间去学习架构设计思想。
- 扩展方便:能够与现有框架较好集成;由于是垂直爬虫,需要针对不同的网页定制爬取规则集逻辑,需要能够方便测试,不要老是重新编译,因此最好支持python等脚本语言
- 功能全面:内置支持ajax/javascript爬取、登录认证、深度爬取设置、类似heritrix的爬取过滤器(filter)、页面压缩处理等
- 管理功能:提供爬虫管理接口,能够实时监控和管理爬取
厌烦了基于java的爬虫方案,尤其是考虑到python在网络编程上的易用性,因此打算考察基于python做新版本爬虫的可行性,刚好把久不使用的python捡起来。
整理了一下目前基于python的crawler,大致有如下一些现成的项目方案可供参考:
Mechanize:http://wwwsearch.sourceforge.net/mechanize/
Twill:http://twill.idyll.org/
Scrapy:http://scrapy.org
HarvestMan:http://www.harvestmanontheweb.com/
Ruya:http://ruya.sourceforge.net/
BeautifulSoup + urllib2:http://www.crummy.com/software/BeautifulSoup/
比较之后,选择Scrapy作为重点考察学习对象,尽管没有Mechanize及Harvestman成熟,但从其架构来看,还是很有前途的,尤其是基于twisted高性能框架的架构,很有吸引力。
看看Scrapy的架构:
Components
The engine is responsible for controlling the data flow between all components of the system, and triggering events when certain actions occur. See the Data Flow section below for more details.
The Scheduler receives requests from the engine and enqueues them for feeding them later (also to the engine) when the engine requests them.
The Downloader is responsible for fetching web pages and feeding them to the engine which, in turns, feeds them to the spiders.
Spiders are custom classes written by Scrapy users to parse response and extract items (aka scraped items) from them or additional URLs (requests) to follow. Each spider is able to handle a specific domain (or group of domains). For more information see Spiders.
The Item Pipeline is responsible for processing the items once they have been extracted (or scraped) by the spiders. Typical tasks include cleansing, validation and persistence (like storing the item in a database). For more information see Item Pipeline.
Downloader middlewares are specific hooks that sit between the Engine and the Downloader and process requests when they pass from the Engine to the downloader, and responses that pass from Downloader to the Engine. They provide a convenient mechanism for extending Scrapy functionality by plugging custom code. For more information see Downloader Middleware.
Spider middlewares are specific hooks that sit between the Engine and the Spiders and are able to process spider input (responses) and output (items and requests). They provide a convenient mechanism for extending Scrapy functionality by plugging custom code. For more information see Spider Middleware.
Spider middlewares are specific hooks that sit between the Engine and the Scheduler and process requests when they pass from the Engine to the Scheduler and vice-versa. They provide a convenient mechanism for extending Scrapy functionality by plugging custom code.
参考资料:
http://doc.scrapy.org
http://stackoverflow.com/questions/419235/anyone-know-of-a-good-python-based-web-crawler-that-i-could-use
http://en.wikipedia.org/wiki/Web_crawler#Open-source_crawlers
http://java-source.net/open-source/crawlers
http://chuanliang2007.spaces.live.com/blog/cns!E5B7AB2851A4C9D2!795.entry
相关推荐
基于Python的网络爬虫技术研究基于Python的网络爬虫技术研究基于Python的网络爬虫技术研究
基于Python的病毒数据爬取系统 基于Python的病毒数据爬取系统 基于Python的病毒数据爬取系统 # virus_data_crawler #### 介绍 基于Python的病毒数据爬取系统 #### 软件架构 后端:flask框架 前端:layui+layuimini...
基于Python的企查查爬虫,爬取完整的公司数据 -------- 该资源内项目源码是个人的毕设,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! <项目介绍> 1、该资源内项目代码都经过...
借助 Python 和 Scrapy 语言框架基础,以“旅游网站”为爬取目标,通过分析当前现有Web crawler 的运行机理、功能单元以及算法程序,试探性的创建一个针对性比较强的网络爬虫,对课题的目标数据...基于Python的旅游网站
1基于Python的网络爬虫 网络爬虫又称网络蜘蛛,或网络机器人。网络爬虫通过网页的 链接地址来查找网页内容,并直接返回给用户所需要的数据,不需 要人工操纵浏览器获取。脚daon是一个广泛使用的脚本语言,其自 带了...
基于Python的新浪微博数据爬虫_周中华基于Python的新浪微博数据爬虫_周中华
基于Python的B站弹幕采集程序(逆向) B站弹幕采集(逆向) 弹幕接口URL的请求参数是被加密的,经过分析之后发现是MD5加密。 用Python直接构造一个加密的参数 安装教程 pip install httpx[http2] 使用说明 找到...
python爬虫 *__运行的机器要能被外网访问,用来接收dht网络节点的信息,使用vps即可__* 1. linux 服务器 2. python 2.7.3 3. 安装 libtorrent 的 python 绑定库 4. 安装 twisted 网络库 5. 开放防火墙的对应...
基于python招聘岗位数据爬虫及可视化分析设计 开发软件:Pycharm + Python3.7 + Requests库爬取 + Mysql + Echarts 兼职招聘分析系统的首页有各类图表的综合分析,用户在打开招聘分析系统后在首页就能看到相应的...
可以爬取指定微博的爬虫,基于Python语言
Python初学者,自己编写的基于Python的爬虫项目
基于Python实现对链家二手房数据进行采集并用CSV进行保存源代码 安装教程 创建虚拟环境并安装 pip install -r requirements.txt 使用说明 找到 housing_crawler.py 文件执行命令行命令 python housing_crawler...
基于python的对话机器人原型设计与基础代码开发+项目说明.zip 1. 非结构化数据挖掘 目标:对非结构化信息进行数据挖掘 非结构化信息包括 文本,文档等 挖掘方式 QA Pair Mining KB Mining 文档结构化 结果保存 ES...
基于python招聘岗位数据爬虫及可视化分析设计 开发软件:Pycharm + Python3.7 + Requests库爬取 + Mysql + Echarts 兼职招聘分析系统的首页有各类图表的综合分析,用户在打开招聘分析系统后在首页就能看到相应的...
新闻网站爬虫,课程设计与人合作完成的小项目,基于python3 scrapy,UI界面采用tkinter,数据库采用mongodb,利用机器学习训练数据,对新闻进行分类,并存储到mongo数据库中,通过用户界面展示出来 目前由于训练集...
基于Python Scrapy实现的网易云音乐music163数据爬取爬虫系统 含全部源代码 基于Scrapy框架的网易云音乐爬虫,大致爬虫流程如下: - 以歌手页为索引页,抓取到全部歌手; - 从全部歌手页抓取到全部专辑; - 通过...
基于Python的某东商品价格监控:自定义商品价格降价邮件-微信提醒.zip 简介 用户自行设定指定商品的监控价格,运行脚本获取价格数据。 申明:本脚本没有涉及JD账号登录,没有抓取任何JD敏感信息,仅在手动执行一次...
基于python机器学习的金融新闻数据挖掘分析系统源码+项目说明+数据.zip 本项目致力于完成金融相关的数据抓取、NLP算法分析、量化策略、回测框架等的系统搭建工作,系统包括如下几个主要的部分; 项目结构 . ├──...