Link to home
Start Free TrialLog in
Avatar of Philippe Renaud
Philippe RenaudFlag for Canada

asked on

Find nodes in HtmlNodeCollection

Hello EE,

I have in my vb.net project HtmlUtilityPack import.

Im trying to find a Div and the result I insert in a HtmlNodeCollection like this :

        Dim nodes As HtmlNodeCollection = doc.DocumentNode.SelectNodes("//div[@id='myID']")

Open in new window


but inside this DIV there are many <a href='www.something.com' title='hello'></a>

I want all the title attribute of al of them. but only in that specific div..

im not sure where to go with this... should be soemthing like :

Dim list as new List(of string)
For Each node As HtmlNode In nodes
  list.add(node.SelectNode("a").GetAttribute('title"))
Next

can you help ?
thanks
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Philippe Renaud

ASKER

yes sorry agility.

but it cant be done on 2 lines? i need to do it on doc.DocumentNode?

i cannot do it on the nodes variable to reach @a?

because otherwise i always need to re-iterate on doc variable and sometimes there is tons of source code lines, but still maybe its fast also.. i dont know
I'm probably not understanding what you are asking, but if you would like to stick with the logic you currently have, then it should be along the lines of:

For Each node As HtmlNode In nodes
  list.add(node.SelectSingleNode("a").Attributes("title").Value)
Next

Open in new window

Thank you