一、环境:
1.操作系统:windowsXp,windows2000+
2.java1.6,设置JAVA_HOME到环境变量
3.cygwin,当然这个不是必需的,只是nutch提供的脚本只能在shell环境下使用,所以使用cygwin来虚拟shell命令。
4.nutch版本:0.9
5.tomcat:6.0
二、nutch的安装和配置:
1,安装Cygwin<chsdate year="1899" month="12" day="30" islunardate="False" isrocdate="False" w:st="on">1.5.5</chsdate>(我这里装到F:/cygSys),将nutch解压缩后放置到cygSys /home/用户名的一个目录下(我放在F:/cygSys/home/dyk/nutch下),如图:
2,在Cygwin环境下进入nutch-0.9目录下,使用命令 bin/nutch进行测试,正常的情况下出现的结果是:
3,进行抓取网站的测试,以抓取http://www.163.com/为例
1) 新建一个文件myurl,在文件中输入http://www.163.com/保存,这个文件可以放在任何地方(我这个文件放在F:/cygSys/home/dyk/nutch/myurl),另外再建立一个爬虫日志目录logs(我放在F:/cygSys/home/dyk/nutch/logs)
2)
打开nutch-0.9/conf/nutch-site.xml文件,在<configuration></configuration>内插入以下内容:
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><property>
<name>http.agent.name</name>
<value></value>
<description>HTTP'User-Agent'requestheader.MUSTNOTbeempty-
pleasesetthistoasingleworduniquelyrelatedtoyourorganization.
NOTE:Youshouldalsocheckotherrelatedproperties:
http.robots.agents
http.agent.description
http.agent.url
http.agent.email
http.agent.version
andsettheirvaluesappropriately.
</description>
</property>
<property>
<name>http.agent.description</name>
<value></value>
<description>Furtherdescriptionofourbot-thistextisusedin
theUser-Agentheader.Itappearsinparenthesisaftertheagentname.
</description>
</property>
<property>
<name>http.agent.url</name>
<value></value>
<description>AURLtoadvertiseintheUser-Agentheader.Thiswill
appearinparenthesisaftertheagentname.Customdictatesthatthis
shouldbeaURLofapageexplainingthepurposeandbehaviorofthis
crawler.
</description>
</property>
<property>
<name>http.agent.email</name>
<value></value>
<description>AnemailaddresstoadvertiseintheHTTP'From'request
headerandUser-Agentheader.Agoodpracticeistomanglethis
address(e.g.'infoatexampledotcom')toavoidspamming.
</description>
</property>
可以把<name>XXX</name>之间的内容替换为其他字符,当然就算是不替换也无所谓,这里的设置,是因为nutch遵守了robots协议,在获取response时,把自己的相关信息提交给被爬行的网站,以供识别。
3)
打开nutch-0.9/conf/crawl-urlfilter.txt文件,把MY.DOMAIN.NAME字符替换为myurl内的域名(比如我改成了“+^http://([a-z0-9]*/.)*163.com/”,其实更简单点,直接删除MY.DOMAIN.NAME这几个字就可以了,也就是说,只保存+^http://([a-z0-9]*/.)*这几个字就可以了,表示所有http的网站都同意爬行)。
<!--[endif]-->
4)
运行爬虫,在Cygwin输入以下命令:
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->bin/nutchcrawl../myurl–dir../mydir–depth2>&../logs/crawl1.log
这里dir表示存储的目录,-depth表示网址爬的深度,最后是指明日志文件
运行结束后,你可以打开日志文件查看爬虫运行的详细过程。
5,在tomcat上运行Nutch
把nutch-0.9.war拷贝到Tomcat/webapps/下面
在浏览器中输入http://localhost:8080/nutch-0.9/这步是为了使tomcat展开nutch-0.9.war,然后修改webapps/ nutch-0.9/WEB-INF/classes/nutch-site.xml文件如下:
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><configuration>
<property>
<name>searcher.dir</name>
<value>F://cygSys//home//dyk//nutch//mydir4</value>
</property>
</configuration>
为了支持中文的搜索,修改Tomcat/conf/server.xml。找到对应的地方修改成
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><Connectorport="8080"protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"URIEncoding="UTF-8"useBodyEncodingForURI="true"/>
在浏览器中输入http://localhost:8080/nutch-0.9,
搜索“nba”,结果是
分享到:
相关推荐
nutch 0.9 版代码包,包含src源代码,war可直接部署到tomcat中的war包,以及爬取网页的可执行文件,nutch crawl文件。
nutch 0.9分页代码(粘贴可用)
Eclipse 编译 Nutch-0.9
Nutch在windows下的安装 JDK安装 Tomcat安装 Cygwin安装
nutch1.4 在windows下的安装配置环境搭建
Nutch在windows下的安装.pdf
Apache Nutch 1.7 在windows和Linux下的安装,有详细的图示和步骤说明,测试过多次。
windows下安装nutch 各异常说明
eclipse配置nutch,eclipse配置nutch
亲测好用
Nutch在windows下的安装[归纳].pdf
本来有机会接个搜索引擎项目但最终因价格问题双方谈崩为此我感到深深遗憾失去了个极好实战机 会但我不想因此放弃对搜索引擎学习和实战在...Nutch还是先从安装和使用Nutch开始吧以下是我在xp sp2环境下安装Nutch过程记录
windows下nutch的安装.pdf
近来Nutch一词在网络中时有所见,但囿于平常工作繁忙而未能潜心细读与研究,只知道Nutch是Apache组织的一个开源项目,利用它用户可以建立自己内部网的搜索...下面,就让笔者对Nutch在Windows系统中的安装进行一番细解吧
详细介绍nutch在windows下myeclipse中的配置以及执行,本人空间还有nutch1.2包,nwgwin安装包等
参考文章 http://blog.csdn.net/handyhuang/article/details/7421553
windows下nutch的安装配置以及与tomcat的集成.doc
nutch 1.4 在windows下安装配置
Windows 下安装使用nutch.doc
NUTCH安装步骤.NUTCH安装步骤.NUTCH安装步骤.NUTCH安装步骤.NUTCH安装步骤.NUTCH安装步骤.NUTCH安装步骤.NUTCH安装步骤.NUTCH安装步骤.