Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Ignore robots.txt when parsing segment, refactored storing of robots.txt in FetcherThread

Sebastian Nagel264eea01a4d8
diff --git a/src/java/org/apache/nutch/fetcher/FetcherThread.java b/src/java/org/apache/nutch/fetcher/FetcherThread.java
index cac16ffdc..6024b8dfe 100644
--- a/src/java/org/apache/nutch/fetcher/FetcherThread.java
+++ b/src/java/org/apache/nutch/fetcher/FetcherThread.java
@@ -264,12 +264,7 @@ public class FetcherThread extends Thread {
.toString());
BaseRobotRules rules = protocol.getRobotRules(fit.url, fit.datum, robotsTxtContent);
if (robotsTxtContent != null) {
- for (Content robotsTxt : robotsTxtContent) {
- LOG.debug("fetched and stored robots.txt {}",
- robotsTxt.getUrl());
- output.collect(new Text(robotsTxt.getUrl()),
- new NutchWritable(robotsTxt));
- }
+ outputRobotsTxt(robotsTxtContent);
robotsTxtContent.clear();
}
if (!rules.isAllowed(fit.u.toString())) {
@@ -758,6 +753,19 @@ public class FetcherThread extends Thread {
return null;
}
+ private void outputRobotsTxt(List<Content> robotsTxtContent) {
+ for (Content robotsTxt : robotsTxtContent) {
+ LOG.debug("fetched and stored robots.txt {}",
+ robotsTxt.getUrl());
+ try {
+ output.collect(new Text(robotsTxt.getUrl()),
+ new NutchWritable(robotsTxt));
+ } catch (IOException e) {
+ LOG.error("fetcher caught: {}", e.toString());
+ }
+ }
+ }
+
private void updateStatus(int bytesInPage) throws IOException {
pages.incrementAndGet();
bytes.addAndGet(bytesInPage);
diff --git a/src/java/org/apache/nutch/parse/ParseSegment.java b/src/java/org/apache/nutch/parse/ParseSegment.java
index b008bed1c..1a0da9080 100644
--- a/src/java/org/apache/nutch/parse/ParseSegment.java
+++ b/src/java/org/apache/nutch/parse/ParseSegment.java
@@ -84,11 +84,14 @@ public class ParseSegment extends NutchTool implements Tool,
key = newKey;
}
- int status = Integer.parseInt(content.getMetadata().get(
- Nutch.FETCH_STATUS_KEY));
- if (status != CrawlDatum.STATUS_FETCH_SUCCESS) {
+ String fetchStatus = content.getMetadata().get(Nutch.FETCH_STATUS_KEY);
+ if (fetchStatus == null) {
+ // no fetch status, skip document
+ LOG.debug("Skipping {} as content has no fetch status", key);
+ return;
+ } else if (Integer.parseInt(fetchStatus) != CrawlDatum.STATUS_FETCH_SUCCESS) {
// content not fetched successfully, skip document
- LOG.debug("Skipping " + key + " as content is not fetched successfully");
+ LOG.debug("Skipping {} as content is not fetched successfully", key);
return;
}