<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> 这个是唯一的。谢谢。

解决方案 »

  1.   

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

  2.   

    这个我一开始就试了,,取不到哦。。elem.GetAttribute("class") 取出来的都是空值。。
      

  3.   

    我知道了,在ie下 getAttribute( "class") 是取不到值的。。
    应该是getAttribute( "className ")让我搞了大半天。。没分了谢谢楼上的。