网络爬行 - 用 Ja​​va 识别网页上的主要内容

发布于 2024-12-11 10:56:31 字数 410 浏览 4 评论 0原文

从事一个小爱好项目,抓取一些网页,主要是我们的用户发布的博客和新闻网站。

我们有一个小脚本,它只需要一个 URL 列表并抓取拉入所有内容的页面,基本上是使用 Apache HTTP 组件的 hello world 版本...

无论如何,我们想对这些上出现的文本进行一些分析页。但由于任何 URL 都可以以任何格式出现,我们需要一些相当可靠的方法来识别网页上的主要内容(这里有一些错误是可以的)。

有谁知道任何开源框架或 Java 中的小脚本可用于识别网页中的主要文本内容?

我想到了几种方法,例如简单地查找具有最可见文本的最大 DOM 元素,或者比较用于描述某些文本(即元数据)与实际文本数据的字符数。我希望有人能在 Java 中发布一些东西来做到这一点,但如果没有,因为我将不厌其烦地这样做,是否需要这样的实用程序?

干杯!

Working on a little hobby project, scraping a few webpages, mostly blogs and news sites that our users post.

We have a little script that simply takes a list of URLs and scrapes the pages pulling in all content, basically the hello world version of using Apache HTTP components...

Anyway, we would like to do some analysis on the text that appears on these pages. But as any URL can appear, in any format, we need some reasonably reliable way to identify the main content on a web page (a few errors here and there are ok).

Is anyone aware of any open source frameworks or little scripts in Java that can be used to Identify the major text content in a web page?

There are a few methods that come to mind like simply looking for the largest DOM element with the most visible text, or comparing the number of chars used to describe some text (i.e. meta-data) vs. actual text data. I was hoping someone may have release something to do this in Java, but if not, as I'm about to go the trouble of doing this, is there a need out there for such a utility?

Cheers!

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

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

发布评论

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

评论(1

何以心动 2024-12-18 10:56:31

我认为 boilerpipe 对您有用。
看看这里:http://code.google.com/p/boilerpipe/

并且这是教程:
http://code.google.com/p/boilerpipe/wiki/QuickStart

对我来说似乎很简单:

URL url = new URL("http://www.example.com/some-location/index.html");   
// NOTE: Use ArticleExtractor unless DefaultExtractor gives better results for you           
String text = ArticleExtractor.INSTANCE.getText(url);

I think boilerpipe is useful for you.
Have a look here: http://code.google.com/p/boilerpipe/

And here is the tutorial:
http://code.google.com/p/boilerpipe/wiki/QuickStart

Seems quite simple to me:

URL url = new URL("http://www.example.com/some-location/index.html");   
// NOTE: Use ArticleExtractor unless DefaultExtractor gives better results for you           
String text = ArticleExtractor.INSTANCE.getText(url);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文