Take the 2-minute tour ×

I try to extract Token2 from the div

I manage to get Token1 and Token3 with :

HtmlNodeCollection headerFooter = doc.DocumentNode.SelectNodes("//div//b");

How can I extract directly Token2 with HTMLAgilityPack ?

One dirty option is to replace Token1 and Token2 by string.empty in doc.DocumentNode.SelectNodes("//div").InnerText, but I imagine it can been done in more clean way with HTMLAgilityPack...

share|improve this question

1 Answer 1

The text is in the text nodes; so you should be able to look at "//div/text()" and concatenate:

StringBuilder sb = new StringBuilder();
foreach (HtmlAgilityPack.HtmlTextNode node in
string s = sb.ToString();
share|improve this answer
Even using text() I will have Token1 and Token3. –  Lazarus Aug 28 '09 at 11:00
No you won't... unless you do //text() or //div/*/text(); //div/text() returns only those directly under the divs. Or for a specific element, SelectNodes("text()") –  Marc Gravell Aug 28 '09 at 11:01
Or in other words... try it ;-p –  Marc Gravell Aug 28 '09 at 11:04
You are right... I tried with //div//text() THANK YOU !!! –  Lazarus Aug 28 '09 at 11:11

Your Answer

