2009-09-17 146 views

回答

3

示例代码:

GeckoElementCollection links = geckoWebBrowser1.Document.GetElementsByTagName("a"); 
foreach (GeckoElement link in links) { 
    Debug.WriteLine(link.GetAttribute("href")); 
} 
0

nsIDOMNode将为您提供DOM遍历功能。您可以从文档节点开始。您可以查看nsInterfaces.cs文件以了解接口详细信息。

5

我知道这是一个老问题,但有人仍可以寻找一个答案。

GeckoNodeCollection nodes = geckoWebBrowser1.Document.GetElementsByName("*"); 
foreach(GeckoNode node in nodes) 
{ 
    //do whatever you need to do with the node .. 
    GeckoElement element = node as GeckoElement; 
    //.. 
} 
+0

7年后,它的工作就像一个魅力! :> – 2017-06-16 14:00:12

0

如果你想使用XPath,你可以用这个尝试:

browser.LoadXml("<MyTag><div>helloworld</div></MyTag>"); 

var r = browser.Document.EvaluateXPath("//div"); 
Assert.AreEqual(1, r.GetNodes().Count()); 

所以在上一个代码:

GeckoElementCollection nodes = browser.Document.EvaluateXPath("//div").GetNodes();  
foreach(GeckoNode node in nodes) 
{ 
    //do whatever you need to do with the node .. 
    GeckoElement element = node as GeckoElement; 
    //.. 
}