How Use From HTMLAgilityPack For Finding A String in nested divs
-
11-12-2019 - |
Question
there is an html codes like below :
<div class="class1 class2 class3">
<div class="class4 class5">
<span class="class6">GOAL STRING</span>
</div>
</div>
now i want to find that GOAL STRING
use from HTMLAgilityPack.
how can i do that?
[with LINQ and without LINQ = please show us both ways]
thanks in advance
Solution
Well you can use xpath to get the span directly.
document.DocumentNode.SelectSingleNode("//div[@class='class1 class2 class3']/div[@class='class4 class5']/span[@class='class6']").InnerText;
This is a good resource for xpath specifically the table in the middle of the page: http://www.codeproject.com/Articles/9494/Manipulate-XML-data-with-XPath-and-XmlDocument-C
Also on Google Chrome you can right click -> inspect element and then right click the element that shows up on the tree and click copy as Xpath to get a starting point. These expressions can usually be simplified.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow