Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Applied patches in NUTCH-56, with minor changes. Submitted by Andy Liu.

Andrzej Bialeckif51c1c1b7dca
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xml
index 07afd8e82..fc66c72c8 100644
--- a/conf/nutch-default.xml
+++ b/conf/nutch-default.xml
@@ -22,6 +22,15 @@
comma-separated, in decreasing order of precedence.</description>
</property>
+<property>
+ <name>http.robots.403.allow</name>
+ <value>true</value>
+ <description>Some servers return HTTP status 403 (Forbidden) if
+ /robots.txt doesn't exist. This should probably mean that we are
+ allowed to crawl the site nonetheless. If this is set to false,
+ then such sites will be treated as forbidden.</description>
+</property>
+
<property>
<name>http.agent.description</name>
<value>Nutch</value>
diff --git a/src/plugin/protocol-http/src/java/org/apache/nutch/protocol/http/RobotRulesParser.java b/src/plugin/protocol-http/src/java/org/apache/nutch/protocol/http/RobotRulesParser.java
index 8d79a28a6..824d1c3c4 100644
--- a/src/plugin/protocol-http/src/java/org/apache/nutch/protocol/http/RobotRulesParser.java
+++ b/src/plugin/protocol-http/src/java/org/apache/nutch/protocol/http/RobotRulesParser.java
@@ -49,6 +49,9 @@ import org.apache.nutch.protocol.ProtocolException;
public class RobotRulesParser {
public static final Logger LOG=
LogFormatter.getLogger("org.apache.nutch.fetcher.RobotRulesParser");
+
+ private static final boolean ALLOW_FORBIDDEN =
+ NutchConf.get().getBoolean("http.robots.403.allow", false);
private static final String[] AGENTS = getAgents();
private static final Hashtable CACHE = new Hashtable();
@@ -378,7 +381,7 @@ public class RobotRulesParser {
if (response.getCode() == 200) // found rules: parse them
robotRules = new RobotRulesParser().parseRules(response.getContent());
- else if (response.getCode() == 403)
+ else if ( (response.getCode() == 403) && (!ALLOW_FORBIDDEN) )
robotRules = FORBID_ALL_RULES; // use forbid all
else
robotRules = EMPTY_RULES; // use default rules
diff --git a/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/RobotRulesParser.java b/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/RobotRulesParser.java
index 6ad7e37f3..98bd8b09e 100644
--- a/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/RobotRulesParser.java
+++ b/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/RobotRulesParser.java
@@ -50,6 +50,9 @@ public class RobotRulesParser {
public static final Logger LOG=
LogFormatter.getLogger("org.apache.nutch.fetcher.RobotRulesParser");
+ private static final boolean ALLOW_FORBIDDEN =
+ NutchConf.get().getBoolean("http.robots.403.allow", false);
+
private static final String[] AGENTS = getAgents();
private static final Hashtable CACHE = new Hashtable();
@@ -380,7 +383,7 @@ public class RobotRulesParser {
if (response.getCode() == 200) // found rules: parse them
robotRules = new RobotRulesParser().parseRules(response.getContent());
- else if (response.getCode() == 403)
+ else if ( (response.getCode() == 403) && (!ALLOW_FORBIDDEN) )
robotRules = FORBID_ALL_RULES; // use forbid all
else
robotRules = EMPTY_RULES; // use default rules