Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How to reconfigure code to output specific values rather than collection?

I currently this code on my app that works great to loop through a page and grab the label of an input value of a form and then print the value to a rich text box.

I am now trying to revamp the code to give me the ID the value if the label contains a specific name.

For instance if the label before the input field contains the word Username then I want the application to output the ID of the input field rather than just everything that has a label.

Here is my current code:

Dim web As HtmlAgilityPack.HtmlWeb = New HtmlWeb()

Dim doc As HtmlAgilityPack.HtmlDocument = web.Load("http://shaggybevo.com/board/register.php%22)

Dim nodes As HtmlNodeCollection

' Keeps track of the labels by the associated control id

Dim labelText As New System.Collections.Generic.Dictionary(Of String, String)

' First, get the labels

nodes = doc.DocumentNode.SelectNodes("//label")

If nodes IsNot Nothing Then

For Each node In nodes

If node.Attributes.Contains("for") Then

Dim sFor As String

' Extract the for value

sFor = node.Attributes("for").Value

' If it does not exist in our dictionary, add it

If Not labelText.ContainsKey(sFor) Then

labelText.Add(sFor, node.InnerText)

End If

End If

Next

End If

nodes = doc.DocumentNode.SelectNodes("//input")

Dim sbText As New System.Text.StringBuilder(500)

If nodes IsNot Nothing Then

For Each node In nodes

' See if this input is associated with a label

If labelText.ContainsKey(node.Id) Then

' If it is, add it to our collected information

sbText.Append("Label = ").Append(labelText(node.Id))

sbText.Append(", Id = ").Append(node.Id)

sbText.AppendLine()

End If

Next

End If

RichTextBox1.Text = sbText.ToString

1 Answer

Relevance
  • 9 years ago

    i don't why people ussly make codes longer it just makes the time to exetute it longer!

    Source(s): T_T
Still have questions? Get your answers by asking now.