[使用geckoWebBrowser的标签文本的值

问题描述 投票:0回答:1

检查下面的代码。我正在使用c#winform应用程序。我在用geckofx geckoWebBrowser获取一些html值。从下面的HTML我想获取文本-Super Deluxe Round Silver Above Ground Winter Pool Cover,但是您可以看到我已经尝试获取该文本的内容,但是它不起作用。你知道我在做什么错吗?如何解决?

C#:

url = @"https://www.homedepot.com/s/0723815359971";
geckoWebBrowser1.Navigate(url);
DateTime now = DateTime.Now;
do
{
    this.Refresh();
    Application.DoEvents();
} while (now.AddMilliseconds(5000) > DateTime.Now);
GeckoHtmlElement element = null;
var geckoDomElement = geckoWebBrowser1.Document.DocumentElement;
if (geckoDomElement is GeckoHtmlElement)
{
    element = (GeckoHtmlElement)geckoDomElement;
    innerHtml = element.InnerHtml;

    title = element.GetElementsByTagName("pod-plp__brand-name")[1].NodeValue;//this is what already tried but not works
    if (title != "")
    {
        MessageBox.Show(title);
    }

}

HTML:

<a class="" data-pos="0" data-request-type="sr" data-pod-type="pr" href="/p/Swimline-16-ft-x-16-ft-Round-Silver-Above-Ground-Super-Deluxe-Winter-Pool-Cover-SD12RD/305609609">
    <span class="pod-plp__brand-name">Swimline</span> 
    Super Deluxe Round Silver Above Ground Winter Pool Cover
    </a>
c# geckofx
1个回答
0
投票

GetElementsByTagName通过HTML选项卡名称获取元素。 (例如a,span,div等)

应该这样(假设您的文档中有一个'a'):element.GetElementsByTagName("a")[0].FirstChild.NextSibling

如果您想要的话,哪个会在'a'中获得第二个元素。

© www.soinside.com 2019 - 2024. All rights reserved.