Nutch是一个优秀的开源的数据爬取框架,我们只需要简单的配置,就可以完成数据爬取,当然,Nutch里面也提供了很灵活的的插件机制,我们随时都可以对它进行二次开发,以满足我们的需求,本篇散仙,先来介绍下,如何在eclipse里面以local模式调试nutch,只有在eclipse里面把它弄清楚了,那么,我们学习起来,才会更加容易,因为,目前大多数人,使用nutch,都是基于命令行的操作,虽然很简单方便,但是想深入定制开发,就很困难,所以,散仙在本篇里,会介绍下nutch基本的调试,以及编译。
下面进入正题,我们先来看下基本的步骤。
序号 | 名称 | 描述 | 1 | 安装部署ant | 编译nutch编码使用 | 2 | 下载nutch源码 | 必须步骤 | 3 | 在nutch源码根目录下,执行ant等待编译完成 | 构建nutch | 4 | 配置nutch-site.xml | 必须步骤 | 5 | ant eclipse 构建eclipse项目 | 导入eclipse中,调试 | 6 | conf目录置顶 | nutch加载时,会读取配置文件 | 7 | 执行org.apache.nutch.crawl.Injector注入种子 | local调试 | 8 | 执行org.apache.nutch.crawl.Generator生成一个抓取列表 | local调试 | 9 | 执行org.apache.nutch.fetcher.Fetcher生成一个抓取队列 | local调试 | 10 | 执行org.apache.nutch.parse.ParseSegment执行contet生一个段文件 | local调试 | 11 | 配置好solr服务 | 检索服务查询 | 12 | 执行org.apache.nutch.indexer.IndexingJob映射solr索引 | local调试 | 13 | 映射完成后,就可以solr里面执行查询了 | 校验结果 |
编译完,导入eclipse的中如下图所示,注意conf文件夹置顶:
nutch-site.xml里面的配置如下:
- <?xml version="1.0"?>
- <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
- <!-- Put site-specific property overrides in this file. -->
- <configuration>
- <property>
- <name>http.agent.name</name>
- <value>mynutch</value>
- </property>
- <property>
- <name>http.robots.agents</name>
- <value>*</value>
- <description>The agent strings we'll look for in robots.txt files,
- comma-separated, in decreasing order of precedence. You should
- put the value of http.agent.name as the first agent name, and keep the
- default * at the end of the list. E.g.: BlurflDev,Blurfl,*
- </description>
- </property>
- <property>
- <name>plugin.folders</name>
- <value>./src/plugin</value>
- <description>Directories where nutch plugins are located. Each
- element may be a relative or absolute path. If absolute, it is used
- as is. If relative, it is searched for on the classpath.</description>