heritrix有5条链,网上有说在extractor链里做处理,该链是抽取链,可以负责解析html页面的内容,然后进一步筛选。但是我目前只想通过判断后缀名筛选出html、htm、shtml、xshtml等文件。因此这样在extractor里做处理就有点牛刀小用的意思,因此我在postprocessor链里做处理。详细介绍如下:
fronitierscheduler是一种postprocessor,它的作用是将extractor中分析得到链接加入到froniter中,以供下一步处理(写文件处理等等)。
具体方法:
1.找到org.archive.crawler.postprocessor包下的frontierscheduler.java文件
2.找到frontierscheduler类的protected void schedule(candidateuri cauri)方法
3.我的改写如下:
protected void schedule(candidateuri cauri) { //将cauri转为string格式 string url = cauri.tostring(); //打印出来查看一下 system.out.println(------ + url); //剔除以特定后缀名结尾的url if(url.endswith(.jpeg) ||url.endswith(.jpg) ||url.endswith(.gif) ||url.endswith(.css) ||url.endswith(.doc) ||url.endswith(.zip) ||url.endswith(.png) ||url.endswith(.js) ||url.endswith(.pdf) ||url.endswith(.xls) ||url.endswith(.rar) ||url.endswith(.exe) ||url.endswith(.txt)){ return; } //将未剔除的文件加入到下一步处理(写入到本地磁盘的处理等等) getcontroller().getfrontier().schedule(cauri); }