Да, вы можете экспортировать содержимое просканированных сегментов.Это не просто, но для меня это хорошо работает.Сначала создайте Java-проект со следующим кодом:
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Text;
import org.apache.nutch.protocol.Content;
import org.apache.nutch.util.NutchConfiguration;
import java.io.File;
import java.io.FileOutputStream;
public class NutchSegmentOutputParser {
public static void main(String[] args) {
if (args.length != 2) {
System.out.println("usage: segmentdir (-local | -dfs <namenode:port>) outputdir");
return;
}
try {
Configuration conf = NutchConfiguration.create();
FileSystem fs = FileSystem.get(conf);
String segment = args[0];
File outDir = new File(args[1]);
if (!outDir.exists()) {
if (outDir.mkdir()) {
System.out.println("Creating output dir " + outDir.getAbsolutePath());
}
}
Path file = new Path(segment, Content.DIR_NAME + "/part-00000/data");
SequenceFile.Reader reader = new SequenceFile.Reader(fs, file, conf);
Text key = new Text();
Content content = new Content();
while (reader.next(key, content)) {
String filename = key.toString().replaceFirst("http://", "").replaceAll("/", "___").trim();
File f = new File(outDir.getCanonicalPath() + "/" + filename);
FileOutputStream fos = new FileOutputStream(f);
fos.write(content.getContent());
fos.close();
System.out.println(f.getAbsolutePath());
}
reader.close();
fs.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Я рекомендую использовать Maven;добавьте следующие зависимости:
<dependency>
<groupId>org.apache.nutch</groupId>
<artifactId>nutch</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>0.23.1</version>
</dependency>
и создайте пакет jar (например, NutchSegmentOutputParser.jar)
Вам необходимо установить Hadoop на свой компьютер.Затем запустите:
$/hadoop-dir/bin/hadoop --config \
NutchSegmentOutputParser.jar:~/.m2/repository/org/apache/nutch/nutch/1.5.1/nutch-1.5.1.jar \
NutchSegmentOutputParser nutch-crawled-dir/2012xxxxxxxxx/ outdir
, где nutch-crawled-dir / 2012xxxxxxxxx / - это каталог для обхода, из которого вы хотите извлечь контент (он содержит подкаталог сегмента), а outdir - это выходной каталог.Имена выходных файлов генерируются из URI, однако косые черты заменяются на « _ ».
Надеюсь, это поможет.