我有一个表格webBrowser1
用于加载 HTML 部分包含以下行的页面的控件:
...
<div class="cls">
Hello World !
</div>
我需要得到innerText
of the div
元素。我尝试了以下方法:
string result = "";
foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("div"))
if (el.GetAttribute("class") == "cls")
{
result = el.InnerText;
}
但上面的代码似乎不起作用,根据对于另一个网站上的类似问题,请参阅解决方案 1 http://www.codeproject.com/Questions/271651/read-data-from-DIV-tag-via-webBrowser-Csharp,据说
首先引起我注意的是:<div class="thin">
没有定义名称div
元素,它定义了它的 CSS 样式类。相反,请使用属性名称(或两者),例如:<div class="thin" name="thin">
.
我怎样才能得到innerText
of the div
元素,如果有一个class
仅属性?
任何帮助将不胜感激。
你应该使用ClassName
代替class
:
if (el.GetAttribute("className") == "cls") { … }
详细信息请参见HtmlElement.GetAttribute("class") 不运行 http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/66677b14-f34f-4d4e-9a03-326839bb536e/.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)