比如CSDN的这个页面http://forum.csdn.net/SList/VC_Basic
其中有二个ID同为"topicListTable"的Table元素。
我用WebBrowser.Document.GetElementById("topicListTable");
只能得到第一个元素,我想得到第二个元素(Table),应该如何办?

解决方案 »

  1.   

    先使用GetElementsByTagName("table"),获取多个元素,遍历,然后GetAttribute("id")==topicListTable试试
      

  2.   

    遍历获取
     HtmlElementCollection htmlTabs = webBrowser1.Document.GetElementsByTagName("table");
                if(htmlTabs!=null&&htmlTabs.length>0)
                {
                    HtmlElement htmlTable = htmlElements[0];
                    HtmlElementCollection htmlRows = htmlElement.GetElementsByTagName("tr");
                    HtmlElementCollection htmlCells = null;
                    foreach (HtmlElement htmlRow in htmlRows)
                    {
                           htmlCells = htmlRow.GetElementsByTagName("td");                   
                            foreach (HtmlElement htmlCell in htmlCells)
                            {
                                                  
                            }
                    }
                }