我正在研究一种算法,该算法将在给定 HTML 文件的情况下尝试挑选出它认为最有可能包含页面大部分内容文本的父元素。例如,它将选择以下 HTML 中的 div“内容”:
<html>
<body>
<div id="header">This is the header we don't care about</div>
<div id="content">This is the <b>Main Page</b> content. it is the
longest block of text in this document and should be chosen as
most likely being the important page content.</div>
</body>
</html>
我想出了一些想法,比如遍历 HTML 文档树到它的叶子,将文本的长度相加,并且只有在父级给我们的内容比子级多的情况下才能查看父级的其他文本。
有没有人尝试过这样的事情,或者知道可以应用的算法?它不必是可靠的,但只要它能够猜出包含大部分页面内容文本的容器(例如,对于文章或博客文章),那就太棒了。