在eclipse下编译运行nutch
来源:互联网 发布:编程笔记本电脑配置 编辑:程序博客网 时间:2024/05/18 22:15
1. 下载Nutch并解压到某个目录下,建议在根目录下。
2. 修改Nutch/conf目录下的nutch-site.xml和crawl-urlfilter.txt两个文件,具体的修改方法如下:
(1) nutch-site.xml:
在<configuration></configuration>中间插入以下内容:
<property>
<name>http.agent.name</name>
<value>Jennifer</value>
<description>HTTP 'User-Agent' request header. MUST NOT be empty -
please set this to a single word uniquely related to your organization.
NOTE: You should also check other related properties:
http.robots.agents
http.agent.description
http.agent.url
http.agent.email
http.agent.version
and set their values appropriately.
</description>
</property>
<property>
<name>http.agent.description</name>
<value>Jennifer</value>
<description>Further description of our bot- this text is used in
the User-Agent header. It appears in parenthesis after the agent name.
</description>
</property>
<property>
<name>http.agent.url</name>
<value>Jennifer</value>
<description>A URL to advertise in the User-Agent header. This will
appear in parenthesis after the agent name. Custom dictates that this
should be a URL of a page explaining the purpose and behavior of this
crawler.
</description>
</property>
<property>
<name>http.agent.email</name>
<value>Jennifer</value>
<description>An email address to advertise in the HTTP 'From' request
header and User-Agent header. A good practice is to mangle this
address (e.g. 'info at example dot com') to avoid spamming.
</description>
</property>
并修改<value></value>中间的值,这里的设置是因为Nutch遵守了robots协议,在获取response时,把自己的相关信息提交给被爬行的网站,以供识别。所以设置成任何你喜欢的值都可以的。
(2) crawl-urlfilter.txt:
找到"+^http://([a-z0-9]*/.)* MY.DOMAIN.NAME/”,将其中的'MY.DOMAIN.NAME/'直接删除。
为了后面的方便,建议在修改完成后将conf文件夹复制一下,并保存在硬盘的其他的地方。
3. 到下面两个页面去下载两个jar文件,他们分别是:
http://nutch.cvs.sourceforge.net/nutch/nutch/src/plugin/parse-mp3/lib/
http://nutch.cvs.sourceforge.net/nutch/nutch/src/plugin/parse-rtf/lib/
下载其中的jid3lib-0.5.1.jar和rtf-parser.jar两个文件,并分别把他们拷贝到Nutch/src/plugin/parse-mp3/lib和Nutch/src/plugin/parse-rtf/lib两个文件夹下。
4. 准备工作做好以后就可以在Eclipse中配置Nutch了。打开Eclipse后,我们开始建立Java project。具体的做法是:
File > New > Project > Java project创建Eclipse项目,给我们的项目命名,然后选择Create project from existing source,并指向你的Nutch目录。
5. 点击Next后我们就能看到用于定义Java build的设置环境。在第一个选项卡source下面,选择conf,在下面可以看到三个连接,我们需要选择第三个:Add project ‘Nutch’ to build path,完成以上步骤之后我们就将conf加入到了classpath中。注意:这里不是指上面的第三个选项卡。
6. 现在需要我们选择Default output folder,在这里我们必须选择Nutch/conf作为它的Default output folder,否则就会找不到crawl-urlfilter.txt,从而不能完成网站的爬行,就会出现我之前一只没有解决的问题,会出现以下提示:
Generator: 0 records selected for fetching, exiting ...
Stopping at depth=0 - no more URLs to fetch.
No URLs to fetch - check your seed list and URL filters.
7. 点击Finish,这时我们就完成了前续的配置工作,这时我们就可点击运行,选择Java Application点击OK,开始让Eclipse自己寻找项目的主类。我们选择Crawl-org.apache.nutch.crawl,点击OK。
8. 这时我们可以回到Nutch/conf目录下看下,我们可以看到里面的内容发生了改变,这时就需要我们还原原来conf下的内容,这时我们在第2步中另外保存的conf文件夹就起到了作用。(当然,新生成的东西并不影响我们的后续爬行工作,我们可以只考虑将原来conf下的内容复制回来,但是我个人觉得为了文件夹的管理和查找方便,我建议将新生成的内容全部删除后在将原来conf下的内容复制回来。还有一点需要我们注意,conf里面不可以有org文件夹,如果有的话delete,否则的话会影响index。)。在nutch下建立文件夹myURL,新建文本文件url.txt,键入爬行的起始URL,保存关闭。
9. 点击菜单中的Run > Open run dialog,选择Java Application分支,选中Arguments选项卡。
在Program arguments中填写爬行命令,如:myURL -dir myPages -depth 2 -topN 50
在VM arguments中填写:-Dhadoop.log.dir=logs -Dhadoop.log.file=hadoop.log
填写完成后,点击apply完成提交。由于我们到目前为止还没有建立需要我们爬行的url地址,所以我们在提交完成后,点击close,然后我们就可以建立需要Nutch爬行的url地址,建好之后,只要我们在点击工具栏上的运行按钮,我们就可以在Console的透视图中看到Nutch爬行的结果了。当然如果我们之前已经建立好了我们需要爬行的url地址,我们就可以直接点击run,这时我们也可以在Console的透视图中看到Nutch爬行的结果。
至此,我们的工作全部完成了,当然我建议在Eclipse里面配置Nutch之前,我们最好能够熟悉在Shell的环境下运行Nutch。如果有什么不对的地方,欢迎大家指正,我也很希望能和大家一起学习有关Nutch的相关内容。
- 在Eclipse下编译和运行Nutch
- 在eclipse下编译运行nutch
- eclipse下运行nutch-2.0
- nutch-0.8在eclipse中运行
- 在Eclipse中调试运行Nutch
- nutch在eclipse上运行时错误
- nutch在eclipse上运行时错误
- nutch-1.4在eclipse中运行
- eclipse运行nutch-1.7
- 在eclipse下编译和运行c#的代码!
- Nutch 在window下如何配置到eclipse中
- nutch 无法在 eclipse下调试的问题
- nutch 无法在 eclipse下调试的问题
- Eclipse中编译Nutch-1.0
- Nutch学习之Win7环境下在eclipse中搭建Nutch+solr+tomcat
- [Eclipse笔记]Just for fun – 在Eclipse下编译和运行C#的代码
- lucene在eclipse下运行
- lucene在eclipse下运行
- Finite State Machine library Introduction
- JDBC DB CONN STRING
- 散户选股的六大不败法则
- “少数决”游戏—欺诈游戏
- 超跌反弹之选牛股技巧
- 在eclipse下编译运行nutch
- 借助于硬件厂商提供的高性能,Android将取得绝对优势
- 论文经典
- CentOS 5.x Linux安装以及使用规范
- Repeater控件的应用
- GNU C 规则表达式入门
- 从Eiffel谈契约式设计
- 在PHP开发中养成7个面向对象的好习惯
- C# Timer 计时器 TimerCallback