A few things that will help you when working with HtmlAgilityPack and XPath expressions.
If run
is an HtmlNode
, then:
-
run.SelectNodes("//div[@class="date"]")
Will will behave exactly likedoc.DocumentNode.SelectNodes("//div[@class="date"]")
-
run.SelectNodes("./div[@class="date"]")
Will give you all the<div>
nodes that are children ofrun
node. It won’t search deeper, only at the very next depth level. -
run.SelectNodes(".//div[@class="date"]")
Will return all the<div>
nodes with that class attribute, but not only next to therun
node, but also will search in depth (every possible descendant of it)
You will have to choose between 2. or 3., depending on which one satisfy your needs 🙂