检查下面的代码。我正在使用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>
答案 0 :(得分:0)
GetElementsByTagName
通过HTML选项卡名称获取元素。 (例如a,span,div等)
应该执行以下操作(假设文档中有单个“ a”):
element.GetElementsByTagName("a")[0].FirstChild.NextSibling
如果想要的话,哪个会获得'a'中的第二个元素。