Nutch中的一些小的问题解决

来源:互联网 发布:caffe安装教程ubuntu 编辑:程序博客网 时间:2024/06/07 09:23

今天主要解决了Nutch中的一些小的问题,下面分别简述一下。

1.网页快照乱码问题

Nutch的网页快照是乱码,解决办法是修改tomcat/webapps/nutch目录下的cached.jsp文件,修改其中的第63行。

原来的代码是:content = new String(bean.getContent(details);

修改后的代码是:content = new String(bean.getContent(details),"gb2312");

2.搜索结果高亮显示

Nutch默认的搜索结果是没有高亮的,解决办法是在关键词中加入html颜色标签。

将 org.apache.nutch.searcher.Summary 第107行 代码 修改为:

public String toString() {
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < fragments.size(); i++) {
      buffer.append(fragments.get(i));
    }
    return "<span style='color:red'>" + buffer.toString()+ "</span>"; 
}

3.抓取页面大小

Nutch默认只抓取一个页面的前65k的内容,在我抓取bbs的时候,会出现只能抓取前几个回帖的内容,所以想抓取整个页面的内容,就要解除65k的限制。解决方法是修改nutch/conf中的nutch-site.xml文件,在文件最后添加以下内容:

<property>
<name>http.content.limit</name>
<value>-1</value>
<description>The length limit for downloaded content, in bytes.
If this value is nonnegative (>=0), content longer than it will be truncated;
otherwise, no truncation at all.
</description>
</property>

原创粉丝点击