VB.NET - HtmlAgilityPack - Get innertext between two tags

html html-agility-pack innertext vb.net

Question

I want to get the inside text between two certain tags while using HTMLAgilityPack, for instance:

<a name="a"></a>Sample Text<br>

I'd want to have the text between</a> and <br> Keywords: Sample Text

How do I go about doing it?

TIA...

1
3
2/15/2014 2:40:22 PM

Accepted Answer

When you get to the anchor, you might make advantage of theNextSibling property:

Dim doc = New HtmlDocument()
doc.LoadHtml("<html><body><a name=""a""></a>Sample Text<br></body></html>")
Dim a = doc.DocumentNode.SelectSingleNode("//a[@name=""a""]")
Console.WriteLine(a.NextSibling.InnerText)
5
9/3/2011 7:03:25 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow