Html Agility Pack - Problem selecting subnode

前端 未结 2 1720
灰色年华
灰色年华 2020-12-08 00:55

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

2条回答
  •  感动是毒
    2020-12-08 01:43

    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

      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

      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 :)

提交回复
热议问题