如何从网页中提取元素的样式? [英] How do you extract the style of an element from a webpage?

查看:139
本文介绍了如何从网页中提取元素的样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个编码的ui,我需要提取样式元素,然后在其中拉出宽度。 这将来自网页。 有什么建议吗? 我根本无法理解。


 


这是标签:


< li style =" width:80%;" class =" current-rating">< / li>


 


所以我需要输入数字80 。


 


提前致谢。


 

解决方案

目前,您必须使用mshtml来验证IE的样式属性。


IHTMLElement2
element = control.NativeElement

IHTMLElement2 ;


IHTMLCurrentStyle
style = element.currentStyle
as
IHTMLCurrentStyle ;


您可以使用style.width获取宽度。请参阅IHTMLCurrentStyle的msdn文档
http://msdn.microsoft.com/en-us/library/aa704104(v=VS.85).aspx  获取完整列表属性。


Vinoth


I am creating a coded ui which I need to extract the style element, and then within that pull the width.  This will be from a webpage.  Any suggestions?  I can't figure it out at all.

 

Here is the tag:

<li style="width: 80%;" class="current-rating"></li>

 

So I'd need to pull in the number 80.

 

Thanks in advance.

 

解决方案

Currently, you've to use mshtml to validate the style properties for IE.

IHTMLElement2 element = control.NativeElement as IHTMLElement2;

IHTMLCurrentStyle style = element.currentStyle as IHTMLCurrentStyle;

You can get the width using style.width. Please refer to msdn documentation of IHTMLCurrentStyle http://msdn.microsoft.com/en-us/library/aa704104(v=VS.85).aspx for the complete list of properties.

Vinoth.


这篇关于如何从网页中提取元素的样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆