Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get innertext between two tags - VB.NET - HtmlAgilityPack

I'm using HtmlAgilityPack and I want to get the inner text between two specific tags, for example:

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

I want to get the innertext between </a> and <br> tags: Sample Text

How can I do it?

TIA...


1 Answers

Once you have reached the anchor you could use the NextSibling 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)
like image 149
Darin Dimitrov Avatar answered Jun 24 '26 08:06

Darin Dimitrov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!