Skip to content Skip to sidebar Skip to footer

Get All Elements In A Nodecollections

I have an html file :

Solution 1:

  1. When you are querying over some node you don't need // at the beginning, if you are adding it query will be executed over whole document.

  2. You need to take first node after selecting, so you need to take node with index 0 not 1

This 2 points will solve your problem, but there are some improvements you can do

  1. Instead of SelecNodes().First() you can user SelectSingleNode()
  2. If you don't need any information about parent nodes you can directly query for child nodes - htmlDocument.SelectNodes("\\span[@class='time']") will do all the work

Post a Comment for "Get All Elements In A Nodecollections"