views:

99

answers:

1

I have a specific html node and i want to get the 2nd aka last direct descendant. So after writing .Descendants("div") i wrote ls.Last(). I actually got the last div in the 2nd descendant. Not what i am expecting. How do i get only the direct descendants? or how do i get the descendant with a specific classname? because "div.postBody" would be a suitable alternative.

+1  A: 

Using XPath would give you what you want. So for direct descendants only you can use -

htmlNode.SelectNodes("/div");

Or if you need to search by specific classname then -

htmlNode.SelectNodes("//div[@class='postBody']");
Rohit Agarwal