I want to export my Asics running plan to iCal and since Asics do not offer this service, I decided to build a little scraper for my own personal use. What I want to do is t
In XPATH, //
means all children and grand children below the current node. So you need to come up with a more restrictive XPATH expression. If you provide the real HTML, and what you're looking for exactly, we can help you dig further.
About the error you have:
.div[@class='date']
is invalid because .
is sticked to div
. You could use div[@class='date']
, or ./div[@class='date']
which I believe are equivalent. This is because .
is an XPATH axe, which is an alias for self
and means "the current node".
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 like doc.DocumentNode.SelectNodes("//div[@class='date']")
run.SelectNodes("./div[@class='date']")
Will give you all the <div>
nodes that are children of run
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 the run
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 :)