如何从 HTML 页面中提取完整的 DOM 树
我必须比较两个网页并分析它们之间是否有任何差异。 问题是:我需要包含每个 DOM 元素(也是通过 javascript 动态添加的元素),并且我需要包含所有应用的 CSS 设置(又名计算样式)。
例如:如果定义了 CSS :hover
设置,当鼠标悬停在元素上时,我需要得到与鼠标未悬停在元素上时不同的结果。
也许我可以对页面的每个元素进行 javascript 迭代,询问每个 css 设置和每个子 DOM 元素。但我认为这会花费很长时间,并且会破坏生成的 DOM 并使其更难以比较。
有什么想法吗?谢谢!!
I have to comparare two web pages and analyse if there is any difference between them.
The problem is: i need to include every DOM element (also the ones that are added dynamically through javascript), AND i need to include all applied CSS settings (aka. computed style).
For example: if there is an CSS :hover
setting defined, I need to get a different result when my mouse is over the element, than when it is not over the element.
Maybe I could make an javascript iteration through every element of the page, ask for every css setting and for every child DOM element. But i think this would take a long time and would blow the resulting DOM and make it more difficult to compare.
Any ideas?? Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 Firefox,XmlSerializer 是您的朋友。
For Firefox, XmlSerializer is your friend.
我会检查一下硒。有一个命令 selenium.getHtmlSource();您可以在 javascript 函数发生后调用它。快速浏览后,我发现了这个
http:// davidlaing.com/2008/12/29/selenium-gotcha-seleniumgethtmlsource-returns-processed-html/
和
需要使用 Java 和 Java 来比较 2 个 html 文档selenium
我确信这不是您所希望的优雅方式,但我希望这能让您开始
I would check out selenium. There is a command selenium.getHtmlSource(); You can call this after a javascript function occurs. After a quick look I found this
http://davidlaing.com/2008/12/29/selenium-gotcha-seleniumgethtmlsource-returns-processed-html/
and
Need to compare 2 html documents using Java & selenium
I am sure its not the elegant way you were hoping for but I hope this will get you started