Html Agility Pack + Get specific node

asp.net c# html-agility-pack

Question

Hello i have a problem with my application. I need to pick out a specific text between two nodes.

The html page looks like this

<td align="right" width="186">Text1</td>
<td align="center" width="51">? - ?</td>
<td width="186">Text2</td>`

I can pick out Text1 and Text2 with:

HtmlNodeCollection cols = doc.DocumentNode.SelectNodes("//td[@width='186']");<br />
foreach (HtmlNode col in cols)<br />
{
    if (col.InnerText == "Text1")
    {
        Label1.Text = col.InnerText;            
    }
}

The reason why i have the if-condition is because there are more td's in the page. And i need to specifically pick out the one who got "Text1" in it.

But the problem is how i can parse out the text "? - ?" There are more text in the document also having the text "? - ?" but i need to pick out specifically the one between my two other nodes..

The result should be Text1 ? - ? Text2 etc..

I guess it has something to do with nextchild or sibling etcetera?

Accepted Answer

You can check col.NextSibling.InnerText.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why