我正在尝试让爬虫在每次连续尝试3次后没有找到相关页面时 "中止 "搜索某个子域。在提取页面的标题和文本后,我开始寻找正确的页面提交到我的solr集合。(我不想添加不符合这个查询的页面)
public void visit(Page page)
{
int docid = page.getWebURL().getDocid();
String url = page.getWebURL().getURL();
String domain = page.getWebURL().getDomain();
String path = page.getWebURL().getPath();
String subDomain = page.getWebURL().getSubDomain();
String parentUrl = page.getWebURL().getParentUrl();
String anchor = page.getWebURL().getAnchor();
System.out.println("Docid: " + docid);
System.out.println("URL: " + url);
System.out.println("Domain: '" + domain + "'");
System.out.println("Sub-domain: '" + subDomain + "'");
System.out.println("Path: '" + path + "'");
System.out.println("Parent page: " + parentUrl);
System.out.println("Anchor text: " + anchor);
System.out.println("ContentType: " + page.getContentType());
if(page.getParseData() instanceof HtmlParseData) {
String title, text;
HtmlParseData theHtmlParseData = (HtmlParseData) page.getParseData();
title = theHtmlParseData.getTitle();
text = theHtmlParseData.getText();
if ( (title.toLowerCase().contains(" word1 ") && title.toLowerCase().contains(" word2 ")) || (text.toLowerCase().contains(" word1 ") && text.toLowerCase().contains(" word2 ")) ) {
//
// submit to SOLR server
//
submit(page);
Header[] responseHeaders = page.getFetchResponseHeaders();
if (responseHeaders != null) {
System.out.println("Response headers:");
for (Header header : responseHeaders) {
System.out.println("\t" + header.getName() + ": " + header.getValue());
}
}
failedcounter = 0;// we start counting for 3 consecutive pages
} else {
failedcounter++;
}
if (failedcounter == 3) {
failedcounter = 0; // we start counting for 3 consecutive pages
int parent = page.getWebURL().getParentDocid();
parent....HtmlParseData.setOutgoingUrls(null);
}
我的问题是,我如何编辑这段代码的最后一行,使我可以检索父 "页面对象",并删除其传出的urls,使爬虫移动到其余的子域.目前,我无法找到一个函数,可以让我从父ID到页面数据,删除urls。
该 visit(...)
方法作为最后一条语句被调用。processPage(...)
(第523行) WebCrawler
).
外链已经被添加到爬虫的 frontier
(并且可能在它们被添加后立即被其他爬虫进程处理)。
您可以通过调节 shouldVisit(...)
或(根据具体使用情况)在 shouldFollowLinksIn(...)
爬行器的