Find Similarities between Blocks of Text between Many HTML Documents?

无人久伴 提交于 2019-12-07 19:42:51

问题


If I have say 20 HTML pages and I want to extract out the shared/similar portions of the documents, what are some efficient ways to do that?

So say for StackOverflow, comparing 10 pages I'd find that the top bar and the main menu bar are the same across each page, so I could extract them out.

It seems like I'd need either a diff program or some complex regexps, but assume I don't have any knowledge of the page/text/html structure beforehand.

Is this possible?


回答1:


You should consider a clone detector such as CloneDR. Good ones compare the structure of thousands of files at once regardless of the formatting, and will tell you what the files have as common elements and how those common elements vary.

CloneDR has been applied to many programming langauges. Its foundation, the DMS Software Reengeering Toolkit, already handles (dirty) HTML, so it would be pretty easy to build an HMTL CloneDR.




回答2:


You don't need any complex regexps; just a simple diff analyzer will do. Just do an (Enumerable) injection, keeping only similar parts as your memo.

Here are some in Ruby:

  • ruby-diff -- Implements the text-diff algorithm from Perl
  • diff-lcs
  • HTMLdiff -- Finds the diff of two strings, and renders with pretty formatting (HTML) (Probably not exactly what you want, unless you can strip away all non-diff material from the output)

Hope this helps!



来源:https://stackoverflow.com/questions/3104075/find-similarities-between-blocks-of-text-between-many-html-documents

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!