在xp下配置运行nutch1.0

 

以下是本人总结网上前人的经验并自己测试过的,今日记录以供备忘,可以顺便给一些人做参考。

 

必要的前提环境:

1、  sun官网下载JDK1.6并安装,配置系统环境变量JAVA_HOME=”JDK的安装路径

2、  http://tomcat.apache.org/下载tomcat6.0并安装

一、下载安装cygwin

http://www.cygwin.com/下载cygwin并安装

在我的机器上本地安装老是出错,如果碰到这种情况,试试在线安装

 

除了选择目录外,其他的用默认设置即可

二、下载nutch并配置

1、从http://www.apache.org/dyn/closer.cgi/lucene/nutch/下载nutch1.0

2、将nutch1.0解压并复制到cygwin的安装目录修改目录名为nutch(也可以不修改)

3、在nutch目录下新建urls目录用于存放搜索的网址,并在urls目录下新建url.txt,然后在txt文件中指定开始搜索的完整网址。

4、配置nutch/conf/nutch_site.xml,在<configuration> </configuration>之间添加

<property>

  <name>http.agent.name</name>

  <value>searcher</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>windows</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>http://www.bitren.com/</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>fiwiner@126.com</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>

5、修改nutch/conf/crawl-urlfilter.txt

找到:#+^http://([a-z0-9]*/.)*MY.DOMAIN.NAME/

修改为:#+^http://([a-z0-9]*/.)*

6、启动cygwin执行命令,转到nutch目录(cd /nutch)然后执行:

bin/nutch crawl urls -dir crawled -depth 4 -threads 4 -topN 50 >&crawledlog.log  开始抓取页面

 

urls指定抓取的网站的目录

-dir指定抓取结果存放到哪里

-depth 指定抓取深度

-threads 指定开启多少个线程进行抓取

-topN 指定每个站点最多抓取多少

>&crawledlog.log 指定日志存放的路径

三、配置服务器

         1、启动服务器,将nutch目录下的nutch-1.0.war改名为nutch.war,再将其复制到tomcat下面的webapps目录下,然后启动服务器,tomcat会主动将该war包解包。进入解压后的文件夹,修改WEB-INF/class/ nutch-site.xml

<configuration>  </configuration> 之间添加,粗体部分是必须的,网上流传的很多教程没有提到

 <property>  

  <name>http.agent.name</name>  

  <value>nutch</value>  

  <description></description>  

</property>  

<!-- file properties -->  

<property>  

 <name>searcher.dir</name> 

 

<!-- 下面的目录自己修改成相对应的-->  

 <value> ****/cygwin/nutch/crawled</value> 

  <description></description>  

</property>  

         2、解决中文乱码

                   修改tomcat/server.xml,找到Connector属性并添加:

<Connector port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443"

               URIEncoding="UTF-8"

               useBodyEncodingForURI="true" />

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值