webBrowser 如何取到div 的class 属性

67676373 2010-09-10 11:23:13
<div class=abc>12345</div>

我的目的是通过webBrowser 取到12345,

如果把class 改为 style
<div style=abc>12345</div>

代码就很简单了

HtmlElementCollection hec = webBrowser1.Document.GetElementsByTagName("div");
foreach (HtmlElement he in hec)
{
if (he.Style="abc")
{
tbox1.Text = he.OuterText;
break;
}
}

为什么class的时候就不能判断呢?

说明:我想要准确的定位。因为可能存在很多div嵌套,内容“12345”也是变化的。。但是 <div class=abc> 这个是唯一的。谢谢。
...全文
1300 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
67676373 2010-09-10
  • 打赏
  • 举报
回复
我知道了,在ie下 getAttribute( "class") 是取不到值的。。
应该是getAttribute( "className ")

让我搞了大半天。。没分了。。。谢谢楼上的。
67676373 2010-09-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wuyq11 的回复:]

HtmlElementCollection elems = webBrowser1.Document.GetElementsByTagName("div");
foreach (HtmlElement elem in elems)
{
if( elem.GetAttribute("class").Equals("abc")){}

}
[/Quote]
这个我一开始就试了,,取不到哦。。elem.GetAttribute("class") 取出来的都是空值。。
wuyq11 2010-09-10
  • 打赏
  • 举报
回复
HtmlElementCollection elems = webBrowser1.Document.GetElementsByTagName("div");
foreach (HtmlElement elem in elems)
{
if( elem.GetAttribute("class").Equals("abc")){}

}

111,119

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧