【问题标题】:How to parse content located in specific HTML tags using nutch plugin?如何使用 nutch 插件解析位于特定 HTML 标签中的内容?
【发布时间】:2023-03-05 22:16:01
【问题描述】:

我正在使用 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 页面的策略的指导。

【问题讨论】:

    标签: nutch


    【解决方案1】:

    您可以使用此插件根据 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>
    

    【讨论】:

    • 当我在“extractors.xml”中尝试上述示例时,Nutch 不会索引到 Solr。如果我删除任何一个 &lt;text&gt; 元素,如果有效。该插件不接受多个&lt;text&gt; 元素?
    • 此插件不适用于 Nutch 最新版本,即 2.X 版本
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 2015-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-02
    相关资源
    最近更新 更多