I would like to return the complete InnerText of a div where a specific text is inside.
For example: I am searching for “hello world” in the HTMLDocument (HTMLAgilityPack) and want to return the complete InnerText of the div where “hello world” was found.
This is what I tried:
HtmlNode textNode = doc.DocumentNode.SelectNodes("//text()[contains(., 'hello world')]/..")
This returned the HtmlNode where the specific text was found.
Now I want to get the first parent div of the textNode to return the complete InnerText.
Thanks in advance
This would do it I think…
And this is probably an even better solution:
or use the Linq-to-XML notation:
Or