samedi 29 avril 2017

C# get innerText from with an child

I am working with a webBrowser in C# and I need to get the text from the link. The link is just a href without a class.

its like this

<div class="class1" title="myfirstClass">
<a href="link.php">text I want read in C#
<span class="order-level"></span>

Shouldn't it be something like this?

HtmlDocument doc = webBrowser1.Document;
HtmlElementCollection col = doc.GetElementsByTagName("div");
HtmlElement element = doc.GetElementById("visual-label visual-label-main");
HtmlElementCollection childDivs = element.Children.GetElementsByName("a");
foreach (HtmlElement childElement in childDivs)
{
    MessageBox.Show(childElement.InnerText);
}




Aucun commentaire:

Enregistrer un commentaire