[英]HTMLElement's GetAttribute(“html”) or GetAttribute(“text”) not returning a value
使用此示例,我如何使用C#HTMLElement的Get Attribute在此行上获取“ GOOGLE CLICK”。 假设使用getElementByTagName吸收了此元素。 我不确定要使用哪种类型的属性,我尝试过在Java上运行的“ html ”和“ text ”(例如element.GetAttribute(“ html”) )属性,但遗憾的是,在c#上却没有。
<a href="www.google.com">GOOGLE CLICK</a>
供参考,这是我尝试运行的C#示例代码。
//web is the current page i am at.
HtmlElementCollection links = web.Document.GetElementsByTagName("a");
foreach (HtmlElement link in links)
{
if (link.GetAttribute("text") == "GoogleClick")
MessageBox.Show(this, "Hooray I got it!");
}
“ Google点击”不是属性,而是内部文本。
HtmlElementCollection links = web.Document.GetElementsByTagName("a");
foreach (HtmlElement link in links)
{
if (link.InnerText == "GoogleClick")
MessageBox.Show(this, "Hooray I got it!");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.