Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-488 - Avoid parsing uneccessary links and get a more relevant outlink list. Thanks to Marcin Okraszewski and Emmanuel Joke.

Dennis Kubes5d2ecf81998f
diff --git a/CHANGES.txt b/CHANGES.txt
index a1181ad4d..816cb2db8 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -147,6 +147,9 @@ Unreleased changes (1.0-dev)
50. NUTCH-562 - Port mime type framework to use Tika mime detection framework.
(mattmann)
+
+51. NUTCH-488 - Avoid parsing uneccessary links and get a more relevant outlink
+ list. (Emmanuel Joke, Marcin Okraszewski via kubes)
Release 0.9 - 2007-04-02
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xml
index 13bc353d2..7da1dff8a 100644
--- a/conf/nutch-default.xml
+++ b/conf/nutch-default.xml
@@ -887,6 +887,16 @@
be ignored.</description>
</property>
+<property>
+ <name>parser.html.outlinks.ignore_tags</name>
+ <value></value>
+ <description>Comma separated list of HTML tags, from which outlinks
+ shouldn't be extracted. Nutch takes links from: a, area, form, frame,
+ iframe, script, link, img. If you add any of those tags here, it
+ won't be taken. Default is empty list. Probably reasonable value
+ for most people would be "img,script,link".</description>
+</property>
+
<!-- urlfilter plugin properties -->
diff --git a/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/DOMContentUtils.java b/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/DOMContentUtils.java
index b4ff13239..0f8d21501 100644
--- a/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/DOMContentUtils.java
+++ b/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/DOMContentUtils.java
@@ -19,6 +19,7 @@ package org.apache.nutch.parse.html;
import java.net.URL;
import java.net.MalformedURLException;
+import java.util.Collection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Stack;
@@ -62,18 +63,30 @@ public class DOMContentUtils {
}
public void setConf(Configuration conf) {
+ // forceTags is used to override configurable tag ignoring, later on
+ Collection<String> forceTags = new ArrayList<String>(1);
+
this.conf = conf;
linkParams.clear();
linkParams.put("a", new LinkParams("a", "href", 1));
linkParams.put("area", new LinkParams("area", "href", 0));
- if (conf.getBoolean("parser.html.form.use_action", false)) {
+ if (conf.getBoolean("parser.html.form.use_action", true)) {
linkParams.put("form", new LinkParams("form", "action", 1));
+ if (conf.get("parser.html.form.use_action") != null)
+ forceTags.add("form");
}
linkParams.put("frame", new LinkParams("frame", "src", 0));
linkParams.put("iframe", new LinkParams("iframe", "src", 0));
linkParams.put("script", new LinkParams("script", "src", 0));
linkParams.put("link", new LinkParams("link", "href", 0));
linkParams.put("img", new LinkParams("img", "src", 0));
+
+ // remove unwanted link tags from the linkParams map
+ String[] ignoreTags = conf.getStrings("parser.html.outlinks.ignore_tags");
+ for ( int i = 0 ; ignoreTags != null && i < ignoreTags.length ; i++ ) {
+ if ( ! forceTags.contains(ignoreTags[i]) )
+ linkParams.remove(ignoreTags[i]);
+ }
}
/**