heritrix3.1.0增量爬取

来源:互联网 发布:kindle软件 编辑:程序博客网 时间:2024/05/14 18:34

感谢这三篇文章

https://webarchive.jira.com/wiki/display/Heritrix/Duplication+Reduction+Processors  这个是官网的文章

http://blog.sina.com.cn/s/blog_5f54f0be0101hdep.html

http://blog.csdn.net/historyasamirror/article/details/6706174

然后在得到摘要时我觉得应该去掉某些字符,例如不停变换的当前时间,这也是在一篇文章中看到的,地址忘了。

在crawler-beans.xml中加入

<span style="font-size:12px;"><bean id="httpContentDigest" class="org.archive.modules.extractor.HTTPContentDigest"><property name="stripRegex" value="fds" /> </bean></span>
这儿是引入位置

<span style="font-size:12px;"><ref bean="fetchHttp"/><ref bean="httpContentDigest"/><ref bean="fetchHistoryProcessor"/></span>
注意顺序。
httpContentDigest中的摘要会将<span style="font-family: Arial, Helvetica, sans-serif;">fetchHttp中的摘要覆盖</span>


fetchHistoryProcessor中会将摘要保存起来,在fetchHttp中有个默认的摘要生成的方法,这个方法没有过滤。

<span style="font-size:12px;">fetchHistoryProcessor<span style="font-family:Arial, Helvetica, sans-serif;">中将摘要保存。</span></span>
<span style="font-size:12px;"><span style="font-family:SimSun;">想要页面没有</span><span style="font-family:Arial, Helvetica, sans-serif;">改变依然返回</span><span style="font-family:FangSong_GB2312;">200的话</span><span style="color: rgb(51, 51, 51); font-family: Arial, sans-serif; line-height: 20px;">setting the </span><span style="color: rgb(51, 51, 51); font-family: Arial, sans-serif; line-height: 20px; widows: auto;">sendIfModifiedSince</span><span style="color: rgb(51, 51, 51); font-family: Arial, sans-serif; line-height: 20px; widows: auto;"> and </span><span style="color: rgb(51, 51, 51); font-family: Arial, sans-serif; line-height: 20px; widows: auto;">sendIfNoneMatch</span><span style="color: rgb(51, 51, 51); font-family: Arial, sans-serif; line-height: 20px; widows: auto;"> properties of FetchHTTP to false</span></span>
<pre style="background-color: rgb(240, 240, 240);"><span style="font-family:SimSun;font-size:12px;"><span style="color: rgb(51, 51, 51); line-height: 20px; widows: auto;">这</span><span style="line-height: 20px; widows: auto;">是官</span><span style="line-height: 20px; widows: auto;">方文档的</span><span style="line-height: 20px; widows: auto;">话,但是我设置为true,</span><span style="line-height: 20px; widows: auto;">依然把整个页面都反回了。感觉要在服务器手动返回302才行</span></span>

另外为了在MirrorWriterProcessor值保存修改的文件,改了一个方法:
<span style="font-size:12px;">protected boolean shouldProcess(CrawlURI curi) {Map[] history = (Map[]) curi.getData().get(RecrawlAttributeConstants.A_FETCH_HISTORY);boolean flg = false;// 已经抓取过的不写入.这里用 history[1] 而不用 history[0],是因为在 FetchHistoryProcessor// 中,会往 history 中加一个新的值进去// 而这个值是没有 A_WRITE_TAG 的,所以实际上上次请求的记录是 history[1]//if (history != null && history[1] != null && history[1].containsKey(RecrawlAttributeConstants.A_WRITE_TAG)) {if(history!= null && history[0] != null                 && history[0].containsKey(A_CONTENT_DIGEST)                && history[1] != null                && history[1].containsKey(A_CONTENT_DIGEST)                && history[0].get(A_CONTENT_DIGEST).equals(history[1].get(A_CONTENT_DIGEST))                ){flg = false;} else {// 没有抓取过.如果获取成功了.写入flg = isSuccess(curi);}return flg;// return isSuccess(curi);}</span>
<span style="font-size:12px;"><span style="background-color: rgb(240, 240, 240);">这个和</span><a target=_blank href="http://blog.sina.com.cn/s/blog_5f54f0be0101hdep.html" style="background-color: rgb(240, 240, 240);">http://blog.sina.com.cn/s/blog_5f54f0be0101hdep.html</a><span style="background-color: rgb(240, 240, 240);">这篇文章有点不同,感觉这篇文章的判断</span><span style="font-family: simsun; line-height: 21px; background-color: rgb(255, 255, 255);">history[1].containsKey(A_WRITE_TAG)这儿肯定成立,</span></span>
<span style="font-size:12px;"><span style="font-family: simsun; line-height: 21px; background-color: rgb(255, 255, 255);">不太对</span></span>

0 0
原创粉丝点击