gpt4 book ai didi

nutch - 如何使用 nutch 插件解析位于特定 HTML 标签中的内容?

转载 作者:行者123 更新时间:2023-12-04 15:12:20 26 4
gpt4 key购买 nike

我正在使用 Nutch 抓取网站,我想解析 Nutch 抓取的 html 页面的特定部分。例如,

  <h><title> title to search </title></h>
<div id="abc">
content to search
</div>
<div class="efg">
other content to search
</div>

我想解析 id ="abc"和 class="efg"等的 div 元素。

我知道我必须创建一个用于自定义解析的插件,因为 Nutch 提供的 htmlparser 插件会删除所有 html 标签、css 和 javascript 内容,只留下文本内容。我引用了这个博客 http://sujitpal.blogspot.in/2009/07/nutch-custom-plugin-to-parse-and-add.html但我发现这是用于解析 html 标签,而我想解析具有特定值的属性的 html 标签。我发现有人提到 Jericho 对解析特定的 html 标签很有用,但我可以找到与 Jericho 相关的 nutch 插件的任何示例。

我需要一些关于如何设计基于具有特定值的属性的标签解析 html 页面的策略的指导。

最佳答案

您可以使用此插件根据 css 规则从页面中提取数据:

https://github.com/BayanGroup/nutch-custom-search

在您的示例中,您可以通过以下方式对其进行配置:

<config>
<fields>
<field name="custom_content" />
</fields>
<documents>
<document url=".+" engine="css">
<extract-to field="custom_content">
<text>
<expr value="#abc" />
</text>
<text>
<expr value=".efg" />
</text>
</extract-to>
</document>
</documents>
</config>

关于nutch - 如何使用 nutch 插件解析位于特定 HTML 标签中的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17972582/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com