Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7003073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:00:50+00:00 2026-05-27T21:00:50+00:00

My app is using htmlagility pack. As of right now I can get all

  • 0

My app is using htmlagility pack. As of right now I can get all the input elements on a form. The problem is that I am getting ALL the input elements by ID. I am trying to narrow it down to only give me input elements of a form by ID that contain exact inner text labels before each input element.

Example:

<label for="email">Email Address:</label>
<input type="text" class="textbox" name="email" id="email" maxlength="50" value="" dir="ltr" tabindex="1" 

I am trying to get the input that has a proceeding label with the inner text of “Email Address”

How would I word this?

Here is my app that grabs ALL input elements by ID.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim doc As HtmlDocument
    Dim web As New HtmlWeb
    doc = web.Load("http://shaggybevo.com/board/register.php")
    Dim docNode As HtmlNode = doc.DocumentNode
    Dim nodes As HtmlNodeCollection = docNode.SelectNodes("//input")
    'SelectNodes takes a XPath expression
    For Each node As HtmlNode In nodes
        'Get all input elements by id
        Dim id As String = node.GetAttributeValue("value", "id")

        'print all input elements by id to form2 richtextbox
        Form2.RichTextBox1.Text = Form2.RichTextBox1.Text & Environment.NewLine & id.ToString & name.ToString()
        Form2.Show()

    Next

End Sub

Thanks guys….I have to say I’ve been studying VB.NET for a while and to date this forum has been awesome…glad I found it..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:00:51+00:00Added an answer on May 27, 2026 at 9:00 pm

    The basic concept here is to get the labels whose for attribute matches the id of the associated input.

    So, we cycle through the labels first and record the label’s text in a dictionary that is keyed by the for value, then we cycle through the inputs and if the id of the input is in the dictionary, we retrieve the value from the dictionary (which is the label text) and show it.

    Note that I have also modified how the data is collected to be more efficient (almost any time you concatenate strings, you should use stringbuilder).

    Here’s the rewritten code:

        Dim web As HtmlAgilityPack.HtmlWeb = New HtmlWeb()
        Dim doc As HtmlAgilityPack.HtmlDocument = web.Load("http://shaggybevo.com/board/register.php")
        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
    
        Form2.RichTextBox1.Text = sbText.ToString
        Form2.Show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I began writing an app using declarative_authorization ( http://github.com/stffn/declarative_authorization ) but I'm now wondering
I'm building an app using Brunch and Backbone.js that is to include nested menus.
I am developing an app using Codeigniter. In this app I got a form
I am developing an app using jquery mobile.. In that i want to show
I'm building app using GAE and wanted to use Django for that. Which patch
Simple rails app using Postgres DB, getting 'integer out of range' error when trying
I have built an app using Qt creator for symbiyan mobile; now, I am
I renamed my android app (using eclipse refactor->rename ) now it crashes before I
I have an app using a UITabBarController, and I have another view that needs
We are building an app using the MVVM pattern, we have controllers that wire

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.