2

我开始玩 GeckoFX。不幸的是,我没有找到任何大的文档。我需要获取页面的 DOM 树。迭代每个元素并获取它的信息。有人可以帮帮我吗?

4

4 回答 4

6

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

GeckoNodeCollection nodes = geckoWebBrowser1.Document.GetElementsByName("*");
foreach(GeckoNode node in nodes)
{
    //do whatever you need to do with the node .. 
    GeckoElement element = node as GeckoElement;
    //..
}
于 2010-12-14T05:58:56.847 回答
3

示例代码:

GeckoElementCollection links = geckoWebBrowser1.Document.GetElementsByTagName("a");
foreach (GeckoElement link in links) {
    Debug.WriteLine(link.GetAttribute("href"));
}
于 2010-01-19T16:34:12.510 回答
0

nsIDOMNode将为您提供 DOM 遍历能力。您可以从 Document 节点开始。您可以查看nsInterfaces.cs文件以获取接口详细信息。

于 2010-01-02T18:48:08.107 回答
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;
    //..
}
于 2017-09-04T16:48:39.027 回答