Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Better handling of redirect URLs:

Andrzej Bialecki775a3d2b76aa
diff --git a/src/java/org/apache/nutch/fetcher/Fetcher.java b/src/java/org/apache/nutch/fetcher/Fetcher.java
index e555c0557..2c63572a9 100644
--- a/src/java/org/apache/nutch/fetcher/Fetcher.java
+++ b/src/java/org/apache/nutch/fetcher/Fetcher.java
@@ -147,13 +147,17 @@ public class Fetcher {
}
ParseStatus ps = handleFetch(fle, output);
if (ps != null && ps.getMinorCode() == ParseStatus.SUCCESS_REDIRECT) {
- url = ps.getMessage();
- url = URLFilters.filter(url);
- if (url != null) {
+ String newurl = ps.getMessage();
+ newurl = URLFilters.filter(newurl);
+ if (newurl != null && !newurl.equals(url)) {
refetch = true;
+ url = newurl;
redirCnt++;
fle = new FetchListEntry(true, new Page(url, NEW_INJECTED_PAGE_SCORE), new String[0]);
- LOG.info(" - content redirect to " + url);
+ LOG.fine(" - content redirect to " + url);
+ } else {
+ LOG.fine(" - content redirect skipped, " +
+ (url.equals(newurl)? "newurl == url" : "prohibited by urlfilter"));
}
}
}
@@ -162,13 +166,18 @@ public class Fetcher {
case ProtocolStatus.TEMP_MOVED: // try to redirect immediately
// record the redirect. perhaps the DB will want to know this.
handleFetch(fle, output);
- url = pstat.getMessage();
- if (url != null) {
+ String newurl = pstat.getMessage();
+ newurl = URLFilters.filter(newurl);
+ if (newurl != null && !newurl.equals(url)) {
refetch = true;
+ url = newurl;
redirCnt++;
// create new entry.
fle = new FetchListEntry(true, new Page(url, NEW_INJECTED_PAGE_SCORE), new String[0]);
LOG.info(" - protocol redirect to " + url);
+ } else {
+ LOG.fine(" - protocol redirect skipped, " +
+ (url.equals(newurl)? "newurl == url" : "prohibited by urlfilter"));
}
break;
case ProtocolStatus.GONE:
diff --git a/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HTMLMetaProcessor.java b/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HTMLMetaProcessor.java
index 1eab7e612..3b1d4f9be 100644
--- a/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HTMLMetaProcessor.java
+++ b/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HTMLMetaProcessor.java
@@ -122,6 +122,7 @@ public class HTMLMetaProcessor {
} catch (Exception e) {
;
}
+ URL refreshUrl = null;
if (metaTags.getRefresh() && idx != -1) { // set the URL
idx = content.toLowerCase().indexOf("url=");
if (idx == -1) { // assume a mis-formatted entry with just the url
@@ -129,7 +130,6 @@ public class HTMLMetaProcessor {
} else idx += 4;
if (idx != -1) {
String url = content.substring(idx);
- URL refreshUrl = null;
try {
refreshUrl = new URL(url);
} catch (Exception e) {
@@ -142,13 +142,19 @@ public class HTMLMetaProcessor {
try {
refreshUrl = new URL(currURL, url);
} catch (Exception e1) {
- ;
+ refreshUrl = null;
}
}
- if (refreshUrl == null) metaTags.setRefresh(false);
- metaTags.setRefreshHref(refreshUrl);
}
}
+ if (metaTags.getRefresh()) {
+ if (refreshUrl == null) {
+ // apparently only refresh time was present. set the URL
+ // to the same URL.
+ refreshUrl = currURL;
+ }
+ metaTags.setRefreshHref(refreshUrl);
+ }
}
}
}