Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Parsing 如何使用ApacheNutch中的爬行来提取html中specefic div的值?_Parsing_Solr_Nutch - Fatal编程技术网

Parsing 如何使用ApacheNutch中的爬行来提取html中specefic div的值?

Parsing 如何使用ApacheNutch中的爬行来提取html中specefic div的值?,parsing,solr,nutch,Parsing,Solr,Nutch,我使用nutch 2.2进行爬行,检索到的数据是metatag,如何使用ApacheNutch中的爬行在html中提取specefic div的值您需要覆盖parsefilter并使用Jsoup选择器来选择特定的div。您必须编写一个插件来扩展HtmlParseFilter以实现您的目标 您可以为此使用一些html解析器,如Jsoup,提取所需的URL并将其添加为大纲链接 HtmlPasseFilter实现示例:- public ParseResult filter(Conten

我使用nutch 2.2进行爬行,检索到的数据是metatag,如何使用ApacheNutch中的爬行在html中提取specefic div的值

您需要覆盖parsefilter并使用Jsoup选择器来选择特定的div。

您必须编写一个插件来扩展HtmlParseFilter以实现您的目标

您可以为此使用一些html解析器,如Jsoup,提取所需的URL并将其添加为大纲链接

HtmlPasseFilter实现示例:-

        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;
            }
publicparseresult过滤器(Content-Content,ParseResult-ParseResult,
HTMLMetaTags元标记,DocumentFragment文档){
//获取html内容
String htmlContent=新字符串(content.getContent(),StandardCharsets.UTF_8);
//使用jsoup或任何其他库解析html。
documentdocument=Jsoup.parse(content.toString(),content.getUrl());
Elements=document.select(
<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>
<!--
    <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>