Web Page..How can I obtain all the web page elements and put them into a textbox?

Joined
Apr 13, 2011
Messages
19
Programming Experience
Beginner
What I need to do is grab all the web page elements on a web page (id, name, etc) and place them into a textbox to view...

Currently I have this

VB.NET:
Dim htmlElements As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
        For Each el As HtmlElement In htmlElements
            If el.GetAttribute("name").Equals("name") Then
                TextBox.Text = el.GetAttribute("value")
            End If
        Next

Thanks
 
How can I grab all elements on web page and display them into a richtextbox?

Here is the code that I am trying to use but it doesn't seem to do anything really.

Got any ideas on how I can do this?

VB.NET:
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
 
        Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
 
        For Each webpageelement As HtmlElement In allelements
            If webpageelement.InnerText = ("Username") Then
                If webpageelement.InnerHtml = ("id") Then
                    RichTextBox1.Text = webpageelement.InnerText
                    RichTextBox1.Text = webpageelement.InnerHtml
 
                End If
            End If
 
        Next
 
    End Sub

I'm trying to figure out how I can grab the page elements like the id="" or name="".

thanks.
 
Last edited:
How can I grab all elements on web page and display them into a richtextbox?
All elements, you already have that; Document.All.
Can you explain what about them you want to display?
 
Hey thanks John for the reply...I am trying to display the id="" or the name="" and then the name of the inner text like username or email address, etc.

More specifically I am trying to display in one run....

Username id="username"
Email Address id="email_address"
etc
etc

Thanks for the help
 
What you're talking about is called attributes and attribute values. Use GetAttribute method to get the value for an attribute.
InnerText/InnerHtml is the content of an element, what is between its start tag and end tag, and is not related to the elements attributes.
 
Back
Top