在 nutch 插件中使用 tika

发布于 2025-01-03 08:52:40 字数 917 浏览 4 评论 0原文

简而言之,我正在实现一个插件,它将获取网页内容并以特殊方式处理它们。

我的主要问题是我想将网页转换为纯文本以便能够处理,我读到tika工具包可以做到这一点

,我找到了这个使用tika解析url的代码,我在filter方法下编写了

 public ParseResult filter(Content content, ParseResult parseResult, HTMLMetaTags metaTags, DocumentFragment doc) 
  {
 byte[] raw = content.getContent();
 ContentHandler handler = new BodyContentHandler();
 Metadata metadata = new Metadata();
 Parser parser = new AutoDetectParser(); 
 parser.parse(new ByteArrayInputStream(raw), handler, metadata, new ParseContext());
 String plainText = handler.toString(); 
 LOG.info("Mime: " + metadata.get(Metadata.CONTENT_TYPE));
 LOG.info("content: " + handler.toString());

      }

元数据的结果。 get(Metadata.CONTENT_TYPE) 是 text/html

但 handler.toString() 是空的!

更新: 我还尝试在解析器方法之后使用这一行

 LOG.info ("Status : "+ new ParseStatus().toString());

,得到以下结果: 状态:未解析(0,0)

In nutch I'm implementing a plug-in that will get the content of webpages and process them in special way.

My main problem is I want to convert webpages to plainText to be able to processed,, I read that tika toolkit can do that

so, I found this code that use tika to parse urls, I write it under filter method

 public ParseResult filter(Content content, ParseResult parseResult, HTMLMetaTags metaTags, DocumentFragment doc) 
  {
 byte[] raw = content.getContent();
 ContentHandler handler = new BodyContentHandler();
 Metadata metadata = new Metadata();
 Parser parser = new AutoDetectParser(); 
 parser.parse(new ByteArrayInputStream(raw), handler, metadata, new ParseContext());
 String plainText = handler.toString(); 
 LOG.info("Mime: " + metadata.get(Metadata.CONTENT_TYPE));
 LOG.info("content: " + handler.toString());

      }

The result of metadata.get(Metadata.CONTENT_TYPE) is text/html

but handler.toString() is empty !

Update:
Also I try to use this line after the parser method

 LOG.info ("Status : "+ new ParseStatus().toString());

and I get this result:
Status : notparsed(0,0)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

指尖上的星空 2025-01-10 08:52:40

由于版本 1.1 Nutch 包含一个 Tika 插件(另请参阅NUTCH-766)应该可以满足您的需求。不知道有没有更全面的文档。您可能想向 Nutch 用户 邮件列表询问更多详细信息(或者这里的某人可以填写在)。

Since version 1.1 Nutch includes a Tika plugin (see also NUTCH-766) that should cover your need. I don't know if there's more comprehensive documentation available. You might want to ask the Nutch users mailing list for more details (or someone here on SO can fill in).

甜点 2025-01-10 08:52:40

正如 Jukka Zitting 所说,Tika 已经在 nutch 中得到了利用。在您粘贴的代码中,没有任何地方将 metadataParseStatus 设置为任何 nutch 特定数据结构。因此您看不到相应的 ParseStatus

As Jukka Zitting said, Tika is already leveraged in nutch. In the code that you pasted, there is no place that you had set the metadata and ParseStatus to any nutch specific data structure. So you dont see the ParseStatus accordingly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文