nutch 配置crawl-urlfilter.txt,regex-urlfilter.txt和nutch-site.xml

  1:解压缩的nutch后,到conf下面修改crawl-urlfilter.txt
# accept hosts in MY.DOMAIN.NAME
+^http://([a-z0-9]*\.)*apache.org/
+^http://([a-z0-9]*\.)*longtask.com/blog/
如果有需要可以继续添加相关的站点.
     2:修改conf下面的nutch-site.xml文件,在<configuration>之间添加以下内容
<property>
  <name>http.agent.name</name>
  <value>longtask</value>
  <description>HTTP ‘User-Agent’ request header. </description>
</property>
<property>
  <name>http.agent.description</name>
  <value>longtask</value>
  <description>Further description of our bot- this text is used in the User-Agent header. 
  </description>
</property>
<property>
  <name>http.agent.url</name>
  <value>http://www.longtask.com/blog/</value>
  <description>A URL to advertise in the User-Agent header. 
  </description>
</property>
<property>
  <name>http.agent.email</name>
  <value>longtask@gmail.com</value>
  <description>An email address to advertise in the HTTP ‘From’ reques header and User-Agent header.
  </description>
</property>
     3:回到到nutch的根目录,进入bin目录,建一个urls的文件夹,在文件夹中建一个nutch.txt的问题件,在文件中加入上面要鉴权的Url地址(抓取的网址(nutch.txt)经过(crawl-urlfilters.xml)过滤后,如果没有内容会在log中报错:Stopping at depth=0 - no more URLs to fetch.)。这个地方用nutch1.0怎么都跑不过,只能换回0.9的版本了。

三:解决搜索动态内容的问题:
     需要注意在conf下面的2个文件:regex-urlfilter.txt,crawl-urlfilter.txt
     # skip URLs containing certain characters as probable queries, etc.
     -[?*!@=] (-改+)
     这段意思是跳过在连接中存在? * ! @ = 的页面,因为默认是跳过所以,在动态页中存在?一般按照默认的是不能抓取到的。可以在上面2个文件中都修改成:
     # skip URLs containing certain characters as probable queries, etc.
     # -[?*!@=]
     另外增加允许的一行
     # accept URLs containing certain characters as probable queries, etc.
     +[?=&]
    意思是抓取时候允许抓取连接中带 ? = & 这三个符号的连接
     注意:两个文件都需要修改,因为NUTCH加载规则的顺序是crawl-urlfilter.txt-> regex-urlfilter.txt

四:运行爬虫,抓取内容:
     打开Cygwin,
     在命令行窗口中输入:  cd nutch的目录/bin
     执行命令:
        sh nutch crawl urls -dir e:/index -depth 3 -threads 4 -topN 50 >& ./log.txt
说明:
-dir  dirnames      设置保存所抓取网页的目录.
-depth  depth   表明抓取网页的层次深度
-delay  delay    表明访问不同主机的延时,单位为“秒”
-threads  threads      表明需要启动的线程数
-topN number    在每次迭代中限制爬行的头几个链接数,默认是Integer.MAX_VALUE
运行结束后,查看log.txt日志,会有爬虫检索网页的详细信息。
     问题的解决:运行的过程中报错:
Stopping at depth=0 - no more URLs to fetch.
No URLs to fetch - check your seed list and URL filters.

 

 

参考实例项目:http://www.lsoba.com

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值