有沒有什麼方法可以在抓取網頁時獲取nutch中每個網頁的html內容?如何從nutch獲取html內容
6
A
回答
-2
是的,有一種方法。看看cache.jsp,看看它如何顯示緩存的數據。
1
試試這個:
public ParseResult filter(Content content, ParseResult parseResult, HTMLMetaTags
metaTags, DocumentFragment doc)
{
Parse parse = parseResult.get(content.getUrl());
LOG.info("parse.getText: " +parse.getText());
return parseResult;
}
然後檢查內容hadoop.log
。
8
是的,你可以acutally出口抓取段的內容。這不是直截了當的,但它對我來說很好。首先,創建具有以下代碼的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-爬-DIR/2012xxxxxxxxx /是你想提取(它包含「段」子目錄)和OUTDIR是輸出目錄的內容抓取的目錄。輸出文件名是從URI生成的,但是,斜線替換爲「_」。
希望它有幫助。
0
它的超級基礎。
public ParseResult getParse(Content content) {
LOG.info("getContent: " + new String(content.getContent()));
Content對象有一個方法getContent(),它返回一個字節數組。只要讓Java用BA創建一個新的String(),並且你已經獲得了nutch所提取的原始html。
我使用Nutch的1.9
這裏有org.apache.nutch.protocol.Content https://nutch.apache.org/apidocs/apidocs-1.2/org/apache/nutch/protocol/Content.html#getContent()
相關問題
- 1. 如何從nutch訪問內容分類中的抓取內容
- 2. 如何從XWalkView獲取html內容?
- 3. PHP preg_match_all - 如何從HTML獲取內容?
- 4. 從html中獲取內容
- 5. 如何獲取HTML標籤的內容?
- 6. 如何獲取html方法的內容?
- 7. 如何獲取HTML元素的內容
- 8. 如何獲取URL的HTML內容?
- 9. 如何獲取html標籤內容
- 10. 如何獲取html元素內容
- 11. 如何從控制器內的html內容中獲取文本?
- 12. Nutch履帶不索引HTML內容
- 13. 如何從HTML中提取內容
- 14. 從url重定向獲取html內容
- 15. 從html文件獲取內容
- 16. 從javascript頁面獲取HTML內容
- 17. 使用jquery從xml獲取Html內容
- 18. 從pdf中獲取html內容url(jsoup)
- 19. 從標籤頁獲取HTML內容
- 20. 從XML節點獲取HTML內容
- 21. 如何在nutch中獲取抓取的頁面內容和相應的URL?
- 22. TinyMCE/Prestashop - 獲取HTML內容
- 23. java:獲取html內容
- 24. 獲取HTML內容提交
- 25. 獲取Div類內容html
- 26. Xamarin Android:獲取HTML內容
- 27. 如何閱讀Nutch索引的內容?
- 28. 從html獲取href內容和src內容
- 29. Nutch不抓取頁面內容
- 30. 如何從Apache httpclient錯誤獲取html內容?
大答案的Javadoc。我爲Spring Batch創建了SequenceFileReader, – 2015-05-06 10:52:41