对于大量文件,是否有一种优雅的方式将每个 DOM 节点的计算样式记录到文件中?
有没有一种优雅的方法来获取网页中每个 DOM 节点的大量文件的计算样式,以便比较这些文件中相似节点的样式数据?
我正在处理大量 HTML 文件(> 500),其中包含来自 MS FrontPage 的相当损坏的 HTML,试图提取样式数据并将其转换为语义标记。在某种程度上,我设法使用正则表达式来做到这一点,但现在它变得太复杂了。我了解到首先使用正则表达式解析 HTML 是一个坏主意,所以我试图找到一种方法让浏览器解析 HTML 并为我提供页面上每个节点的计算样式。
我知道我可以使用 JavaScript 访问 DOM 并获取每个节点的计算样式,但我一次只能对一个文件执行此操作,并且没有简单的方法可以跨多个文件比较此数据,或者有吗?如果我没记错的话,不可能将数据从 JavaScript 转储到文件中。还有哪些替代方案?
(顺便说一句。我尝试过使用 HTMLTidy,但 HTML 太糟糕了,以至于崩溃了。)
Is there an elegant way to get the computed style for each DOM node in a web page, for a large number of files, in order to compare style data for similar nodes across those files?
I'm working on a large number of HTML files (> 500) containing pretty broken HTML from MS FrontPage, trying to extract style data and convert it to semantic markup. I managed to do this using regex up to a certain point, but now it's become too complex. I learned that it's a bad idea to parse HTML using regex in the first place, so I'm trying to find a way to have the browser parse the HTML and give me the computed style for each node on the page.
I know I can access the DOM and get the computed style for each node using JavaScript, but I can only do this for one file at a time, and there is no easy way to compare this data across several files, or is there? If I'm not mistaken, it's not possible to dump data from JavaScript to a file. What alternatives would there be?
(BTW. I've tried to use HTMLTidy, but the HTML is so borked that it crashes.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用此: https://github.com/peol/jquery-compulated-style
You could try using this: https://github.com/peol/jquery-computed-style