Html Agility Pack – Problem selecting subnode

A few things that will help you when working with HtmlAgilityPack and XPath expressions.

If run is an HtmlNode, then:

  1. run.SelectNodes("//div[@class="date"]")

    Will will behave exactly like doc.DocumentNode.SelectNodes("//div[@class="date"]")

  2. 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.

  3. 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 🙂

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)