heritrix如果不对链接做筛选的话后期工作是无法进行的。
heritrix有多个扩展点,这里我扩展FrontierSchedule,它是一个PostProcessor,它的作用是在Extractor 中所分析的
链接加到Frontier中。我写了CarFrontirer这个继承了FrontierSchedule的类对本项目的链接进行扩展:
- package userP;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import org.archive.crawler.datamodel.CandidateURI;
- import org.archive.crawler.postprocessor.FrontierScheduler;
- public class CarFrontier extends FrontierScheduler {
- private static final long serialVersionUID = 1L;
- // Pattern p =
- // Pattern.compile("http://price.pcauto.com.cn/m//d+/|robots.txt|dns:*");
- Pattern p = Pattern.compile("http://price.pcauto.com.cn/m//d+/");
- public CarFrontier(String name) {
- super(name);
- }
- protected void schedule(CandidateURI caUri) {
- String url = caUri.toString();
- Matcher m = p.matcher(url);
- if (m.matches() || url.indexOf("robots.txt") != -1
- || url.indexOf("dns:") != -1) {
- this.getController().getFrontier().schedule(caUri);
- } else {
- return;
- }
- }
- }
扩展了FrontierSchedule后,要在/conf/modules/Processor.options中加入刚才写CarFrontier这个类,并在WEB控制台Model中的post processors中选择CarFrontier,这样就可以使用了。