質問

Using this example how can i get the "GOOGLE CLICK" on this line using C# HTMLElement's Get Attribute. assuming that this element was absorbed using getElementByTagName. I am not sure what kind of attribute to use I've tried "html" & "text" (ex. element.GetAttribute("html")) attribute which is working on java, but sadly not on c#.

<a href="www.google.com">GOOGLE CLICK</a>

for reference here is my c# example code that i am trying to run.

//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 Click" is not an attribute but inner text.

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帰属
所属していません StackOverflow
scroll top