如何确定html中每个节点的css文本 [英] How determine css text of each node in html
问题描述
如何迭代网页的HTML节点并获取其中每个节点的CSS文本?我需要的东西像Firebug在做什么,如果你点击一个节点,它给你所有的CSS文本与该节点(甚至是继承的风格)相关联的完整列表。
How can I iterate over HTML nodes of a web page and get the CSS Text of each node in it? I need something like what Firebug is doing, if you click on a Node, it gives you complete list of all CSS Texts associated with that Node (even inherited styles).
我的主要问题不是实际上迭代HTML节点。我正在使用 Html Agility Pack 库。我只需要为每个节点获取完整的CSS。
My main problem is not actually iterating over HTML nodes. I am doing it with Html Agility Pack library. I just need to get complete CSS for each node.
p.s。对不起,我应该说明我想在C#中执行此操作(不是javascript)
p.s. I am sorry, I should have explained that I want to do this in C# (not javascript)
推荐答案
片段对页面中的所有元素有用,并且它们的CurrentStyle属性显示它们的计算风格:
I found the following code snippet useful for all element in the page and 'CurrentStyle' property of them shows their computed style:
HTMLDocument doc = (HTMLDocument)axWebBrowser1.Document;
var body = (HTMLBody)doc.body;//current style
var childs = (IHTMLDOMChildrenCollection)body.childNodes;
var currentelementType = (HTMLBody)childs.item(0);
var width = currentelementType.currentStyle.width;
请注意,根据我的上一篇文章,axWebBrowser1是一个WebBrowser控件。
Note that according to my prev post axWebBrowser1 is a WebBrowser control.
这篇关于如何确定html中每个节点的css文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!