仅获取网站的相关部分

发布于 2025-01-04 02:35:14 字数 816 浏览 3 评论 0原文

Evernote 的 Web Clipper 插件宣布插件仅获取相关文章/帖子/内容部分页面的?这是 Evernote 插件的屏幕截图:

在此处输入图像描述

无论您访问哪个网站,它都与其他布局完全不同,这些总是能够让您获得页面的文章/帖子/内容部分。

每个网站都有不同的布局,有些有侧边栏,有些没有,不同的标签,对于主/文章/内容部分,有些使用

HTML5 其他人使用

; >

,有些使用

>

和其他根本不使用。因此,标签的组合以及网站的布局都有不同的组合。

任何人都可以建议通过 Javascript 或 PHP 获取 ma​​in 文章/帖子/内容的解决方案吗?

How does Evernote's Web Clipper plugin or Announcify plugin only get relevant article/post/content part of the page? Here is an screenshot from evernote plugin:

enter image description here

No matter which website you visit which is completely different from other layout wises, these are always able to get you article/post/content part of the page.

Each website has different layouts, some have sidebar, some don't, different tags, for main/article/content part, some use <article> or <section> of HTML5 others use <h1> > <p>, some use <h2> > <p> and others don't use at all. So there are different combination of tags as well as layouts of websites.

Can anyone suggest a solution to getting main article/post/content please via Javascript or PHP?

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

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

发布评论

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

评论(2

笑着哭最痛 2025-01-11 02:35:15

您可以进行简单的 DOM 解析并搜索包含更多文本的

文本!不是 HTML 代码!< /强>)。然而,无论您选择哪种智能方法来确定内容的位置,您都应该从 DOM 解析开始,所以让我们看一下 DOM 解析 PHP 库。

无论如何,你可以从这里开始:

http://w-shadow。 com/blog/2008/01/25/从网页中提取主要内容/

看起来相当不错,如果你想写一些自己的东西,并给出技术解释。

You can do a simple DOM parsing and search for the <div>s and <p>s containing more text (text! not HTML code!). However, regardless of the intelligent method you will choose for determining where the content is, you should start from DOM parsing, so let's have a look at DOM parsing PHP libraries.

Anyway, you can start from this:

http://w-shadow.com/blog/2008/01/25/extracting-the-main-content-from-a-webpage/

Looks quite good, and gives technical explanations if you want to write something of your own.

可遇━不可求 2025-01-11 02:35:15

大多数博客引擎都会为该 div 提供“内容”的 id。

  • 在 javascript 中,您只需执行 $('#content')
  • 在 php 中,您将执行 DOMDocument::getElementById('content')。

Most blog engines give that div an id of 'content'.

  • In javascript you would just do $('#content')
  • In php you would do DOMDocument::getElementById('content').
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文