您的位置:首页 > 其它

Nutch几个相关问题整理

2014-11-24 17:11 260 查看
1. 如何绕过目标站点的robots.txt限制

多数站点都是只允许百度、google等搜索引擎抓取的,所以会在robots.txt里限制其他爬虫。
nutch自然是会遵循robots协议的,但是我们可以通过修改nutch源码来绕过限制。
相关代码位于:org.apache.nutch.fetcher.Fetcher的run方法.
找到以下几行代码并注释掉就OK了。

if (!rules.isAllowed(fit.u)) {
// unblock
fetchQueues.finishFetchItem(fit, true);
if (LOG.isDebugEnabled()) {
LOG.debug("Denied by robots.txt: " + fit.url);
}
output(fit.url, fit.datum, null, ProtocolStatus.STATUS_ROBOTS_DENIED, CrawlDatum.STATUS_FETCH_GONE);
reporter.incrCounter("FetcherStatus", "robots_denied", 1);
continue;
}


2. url掉转导致html parse不成功的问题

在抓取百度百科的景点数据时,发现部分页面不会走html parse部分的逻辑,而我的plugin是基于HtmlParserFilter扩展点的,因而没有生效。后 来发现请求部分页面的链接返回的http状态为301,跳转之后才会到真正页面,而nutch默认是不会抓取跳转后的页面的.这时需要修改 nutch-site.xml,加入以下配置即可,nutch-default.xml里的默认值是0,我们这里改成一个大于0的值,nutch就会继续 抓取跳转后的页面了。

<property>
<name>http.redirect.max</name>
<value>2</value>
<description>The maximum number of redirects the fetcher will follow when
trying to fetch a page. If set to negative or 0, fetcher won't immediately
follow redirected URLs, instead it will record them for later fetching.
</description>
</property>


3.其他

http://www.atlantbh.com/apache-nutch-overview/ 对nutch的整体流程做了介绍
http://www.atlantbh.com/precise-data-extraction-with-apache-nutch/ 用实际例子介绍了nutch plugin的开发和部署
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: