我不使用Nutch 2.2和數據,我檢索爬行的元標記,如何在Apache的Nutch的爬行提取specefic DIV的HTML值如何通過在apache nutch中爬行來提取html中specefic div的值?
2
A
回答
2
你需要重寫parsefilter和使用Jsoup選擇選擇特定的div。
3
您將不得不編寫一個插件來擴展HtmlParseFilter以實現您的目標。
您可以使用一些像Jsoup這樣的html解析器來提取這個URL並提取您想要的URL並將它們添加爲outlinks。
樣品HtmlParseFilter實現: -
public ParseResult filter(Content content, ParseResult parseResult,
HTMLMetaTags metaTags, DocumentFragment doc) {
// get html content
String htmlContent = new String(content.getContent(), StandardCharsets.UTF_8);
// parse html using jsoup or any other library.
Document document = Jsoup.parse(content.toString(),content.getUrl());
Elements elements = document.select(<your_css_selector_query);
// modify/select only required outlinks
if (elements != null) {
Outlink outlink;
List<String> newLinks=new ArrayList<String>();
List<Outlink> outLinks=new ArrayList<Outlink>();
String absoluteUrl;
Outlink outLink;
for (Element element : elements){
absoluteUrl=element.absUrl("href");
if(includeLinks(absoluteUrl,value)) {
if(!newLinks.contains(absoluteUrl)){
newLinks.add(absoluteUrl);
outLink=new Outlink(absoluteUrl,element.text());
outLinks.add(outLink);
}
}
}
Parse parse = parseResult.get(content.getUrl());
ParseStatus status = parse.getData().getStatus();
Title title = document.title();
Outlink[] newOutLinks = (Outlink[])outLinks.toArray(new Outlink[outLinks.size()]);
ParseData parseData = new ParseData(status, title, newOutLinks, parse.getData().getContentMeta(), parse.getData().getParseMeta());
parseResult.put(content.getUrl(), new ParseText(elements.text()), parseData);
}
//return parseResult with modified outlinks
return parseResult;
}
使用Ant構建新的插件和Nutch的-site.xml中添加插件。
<property>
<name>plugin.includes</name>
<value>protocol-httpclient|<custom_plugin>|urlfilter-regex|parse-(tika|html|js|css)|index-(basic|anchor)|query-(basic|site|url)|response-(json|xml)|summary-basic|scoring-opic|urlnormalizer-(pass|regex|basic)|indexer-elastic</value>
</property>
而且在解析器plugins.xml您可以使用自定義插件,而不是使用蒂卡通過這樣的默認插件: -
<!--
<mimeType name="text/html">
<plugin id="parse-html" />
</mimeType>
<mimeType name="application/xhtml+xml">
<plugin id="parse-html" />
</mimeType>
-->
<mimeType name="text/xml">
<plugin id="parse-tika" />
<plugin id="feed" />
</mimeType>
<mimeType name="text/html">
<plugin id="<custom_plugin>" />
</mimeType>
<mimeType name="application/xhtml+xml">
<plugin id="<custom_plugin>" />
</mimeType>
相關問題
- 1. 如何讓apache nutch永久爬取
- 2. Apache nutch不再爬行
- 3. 如何加快在Nutch中爬行
- 4. 在Nutch中增量爬行
- 5. 獲取Nutch爬行狀態?
- 6. Nutch問題執行爬行
- 7. 如何通過在DataTable中提供列名來獲取行值
- 8. 如何在爬行時製作Apache Nutch索引
- 9. nutch爬行路徑
- 10. 如何讓Nutch的爬蟲抓取
- 11. 如何使用Nutch的-2.2.1爬行
- 12. 如何給深度的nutch 2.3爬行
- 13. 空的Nutch爬行列表
- 14. 如何在Nutch中只抓取HTML?
- 15. nutch是否爬過窗體?
- 16. 無法啓動Nutch爬行
- 17. 如何通過在html中使用id來獲取表格行?
- 18. MongoDB的Apache nutch爬蟲沒有獲取正確的URL
- 19. 通過JS從HTML原始DIV文本中提取div數據
- 20. 在Solr中使用Nutch爬蟲
- 21. 的Web爬行使用Solr的Nutch的
- 22. 如何在Apache中提供通過HTTP API提交的包Ace
- 23. 如何讓Apache Nutch的抓取永遠
- 24. 在Windows 7中運行Apache Nutch
- 25. 刪除從HTML菜單中的爬行索引或者使用Nutch和Solr
- 26. 如何通過單擊html項目來獲取div的前一個文本值?
- 27. apache nutch通過REST索引到索引
- 28. 用nutch 1.8爬行不同的網站
- 29. Nutch的履帶被爬行'作爲€
- 30. apache nutch - 如何通過REST更改插件的配置