Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-2433 / Html Parser: keep htmltag where the outlinks are found

Marcos Bori7db11734f25a
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xml
index c406907c5..c306e82af 100644
--- a/conf/nutch-default.xml
+++ b/conf/nutch-default.xml
@@ -1307,6 +1307,13 @@
for most people would be "img,script,link".</description>
</property>
+<property>
+ <name>parser.html.outlinks.htmlnode_metadata_name</name>
+ <value>htmlnode</value>
+ <description>if not empty, the source nodename of a found outlink will
+ be set in the metadata with this name into the outlink</description>
+</property>
+
<property>
<name>htmlparsefilter.order</name>
<value></value>
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 0d6b2a9aa..32fd5fbdf 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
@@ -28,6 +28,8 @@ import org.apache.nutch.parse.Outlink;
import org.apache.nutch.util.NodeWalker;
import org.apache.nutch.util.URLUtil;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.io.MapWritable;
+import org.apache.hadoop.io.Text;
import org.w3c.dom.*;
@@ -39,6 +41,9 @@ import org.w3c.dom.*;
*
*/
public class DOMContentUtils {
+
+ private String srcTagMetaName;
+ private boolean keepNodenames;
public static class LinkParams {
public String elName;
@@ -88,6 +93,11 @@ public class DOMContentUtils {
if (!forceTags.contains(ignoreTags[i]))
linkParams.remove(ignoreTags[i]);
}
+
+ //NUTCH-2433 - Should we keep the html node where the outlinks are found?
+ srcTagMetaName = this.conf
+ .get("parser.html.outlinks.htmlnode_metadata_name");
+ keepNodenames = (srcTagMetaName != null && srcTagMetaName.length() > 0);
}
/**
@@ -428,6 +438,15 @@ public class DOMContentUtils {
URL url = URLUtil.resolveURL(base, target);
outlinks.add(new Outlink(url.toString(), linkText.toString()
.trim()));
+
+ // NUTCH-2433 - Keep the node name where the URL was found into
+ // the outlink metadata
+ if (keepNodenames) {
+ MapWritable metadata = new MapWritable();
+ metadata.put(new Text(srcTagMetaName), new Text(nodeName));
+ outlinks.get(outlinks.size() - 1).setMetadata(metadata);
+ }
+
} catch (MalformedURLException e) {
// don't care
}