六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 1735|回复: 0

nutch 0.9在Windows下的安装

[复制链接]
 楼主| 发表于 2014-12-2 13:54:45 | 显示全部楼层 |阅读模式
一、环境:
      1.
操作系统:windowsXp,windows2000+
      2.java1.6
,设置JAVA_HOME到环境变量
      3.cygwin,
当然这个不是必需的,只是nutch提供的脚本只能在shell环境下使用,所以使用cygwin来虚拟shell命令。
      4.nutch
版本:0.9
      5.tomcat
6.0
二、nutch的安装和配置:
1,安装Cygwin1.5.5(我这里装到F:cygSys,nutch解压缩后放置到cygSys home用户名的一个目录下(我放在F:cygSyshomedykutch),如图:

2,在Cygwin环境下进入nutch-0.9目录下,使用命令 bin/nutch进行测试,正常的情况下出现的结果是:


3,进行抓取网站的测试,以抓取http://www.163.com/为例
1) 新建一个文件myurl,在文件中输入http://www.163.com/保存,这个文件可以放在任何地方(我这个文件放在F:cygSyshomedykutchmyurl,另外再建立一个爬虫日志目录logs(我放在F:cygSyshomedykutchlogs)
2)打开nutch-0.9confutch-site.xml文件,在内插入以下内容:
  1. <property>
  2.   <name>http.agent.name</name>
  3.   <value></value>
  4.   <description>HTTP 'User-Agent' request header. MUST NOT be empty -
  5.   please set this to a single word uniquely related to your organization.
  6.   
  7.   NOTE: You should also check other related properties:
  8.   
  9.      http.robots.agents
  10.      http.agent.description
  11.      http.agent.url
  12.      http.agent.email
  13.      http.agent.version
  14.   
  15.   and set their values appropriately.
  16.   
  17.   </description>
  18. </property>
  19.   
  20. <property>
  21.   <name>http.agent.description</name>
  22.   <value></value>
  23.   <description>Further description of our bot- this text is used in
  24.   the User-Agent header.  It appears in parenthesis after the agent name.
  25.   </description>
  26. </property>
  27.   
  28. <property>
  29.   <name>http.agent.url</name>
  30.   <value></value>
  31.   <description>A URL to advertise in the User-Agent header.  This will
  32.    appear in parenthesis after the agent name. Custom dictates that this
  33.    should be a URL of a page explaining the purpose and behavior of this
  34.    crawler.
  35.   </description>
  36. </property>
  37.   
  38. <property>
  39.   <name>http.agent.email</name>
  40.   <value></value>
  41.   <description>An email address to advertise in the HTTP 'From' request
  42.    header and User-Agent header. A good practice is to mangle this
  43.    address (e.g. 'info at example dot com') to avoid spamming.
  44.   </description>
  45. </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的网站都同意爬行)。
4)运行爬虫,Cygwin输入以下命令:
  1. bin/nutch crawl ../myurl –dir ../mydir –depth 2 >&../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文件如下:
  1. <configuration>
  2. <property>
  3.   <name>searcher.dir</name>
  4.   <value>F:\\cygSys\\home\\dyk\\nutch\\mydir4</value>
  5. </property>
  6. </configuration>
复制代码
为了支持中文的搜索,修改Tomcat\conf\server.xml。找到对应的地方修改成
  1. <Connector port="8080" protocol="HTTP/1.1"
  2.                connectionTimeout="20000"
  3.                redirectPort="8443" URIEncoding="UTF-8" useBodyEncodingForURI="true"/>
复制代码
在浏览器中输入http://localhost:8080/nutch-0.9

搜索“nba”,结果是


摘自:http://phinecos.cnblogs.com/ 


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博账号登陆

x
该会员没有填写今日想说内容.
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表