Help searching through nodes. Very basic.

Topics: User Forum
Jan 13, 2011 at 3:56 PM
Edited Jan 13, 2011 at 6:56 PM

I'm using VB.net. I'm able to successfully parse through the HTML and return 20 nodes that I'm interested in by doing the following.

 

        Dim WebGet = New HtmlWeb()
        Dim Document = WebGet.Load(Forum)
        Dim i As Integer = 0
  For Each Thread In Document.DocumentNode.SelectNodes("//tr[@class='title']") i = i + 1 Next MsgBox(i)
Doing this i can individually load a node into my HTMLNode object "Thread".

What i can't figure out is how to search for ChildNodes in the Node i just loaded into "Thread". I need to search through each node
and find the InnerHTML values of it's child nodes.

For instance, each node in Thread will have a child node with attribute "username". I need to find that child node, and retrieve it's InnterHTML
Jan 13, 2011 at 10:26 PM

It may just be missing: ... Thread.ToString() ... just started learning this but that's the first thing I'd try.

hth,

tom

Jan 13, 2011 at 11:09 PM

I worked around it by finding the index of the child node in Thread, and then just using:

Thread.DescendantNodes(10)

It only works if the nodes on my page remain pretty much static, which they do, so it will work for me. I still wish there was a slightly more elegant way to search for child nodes within nodes.

Jan 13, 2011 at 11:46 PM

Selecting produces collections, you're collecting attributes, i.e. "class", and I think that's the problem, nodes are tags, attributes aren't.

Think that's why you had to use an index, because you have a collection of different tags all with the same attribute. If you select a tag collection, the children will be tags.

hth, tom