html agility pack ~ how can I get all inputs of a form~ error code given

simpleonline12

New member
Sep 29, 2009
191
3
0
Code:
Imports System.Net
Imports System.IO
Imports System.Text


Imports HtmlAgilityPack

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        HtmlNode.ElementsFlags.Remove("form")
        Dim doc As New HtmlDocument()
        doc.LoadHtml("http://mywebsiteishere/")
        Dim secondForm As HtmlNode = doc.GetElementbyId("form2")
        For Each node As HtmlNode In secondForm.Elements("input")
            Dim valueAttribute As HtmlAttribute = node.Attributes("value")
            If valueAttribute IsNot Nothing Then
                Console.WriteLine(valueAttribute.Value)
            End If
        Next





    End Sub
End Class


And here is my error code.

examplek.jpg


What I am trying to do is to navigate to a website and download all the inputs of the form on that page. Doesn't matter what website I use I can't get beyond this error code.

Any ideas?

Thanks
 


Try to check if "form2" and "input" exist on the web page. Also make sure secondForm is not null.
 
To add to the previous post.

The method secondForm.Elements(string name) needs the name of an element. "input" seems to be the type of an element/control not the name of an element.
 
Awesome....yeah they weren't on the page. So how can I code it to be general purpose?

I'm wanting to navigate to any website and grab the input elements from the html.

I was told that HTML agility pack was the easiest to use for this method.

Got any ideas?

Thanks
 
Use DocumentNode.SelectNodes() to get all the form input controls
 
Sweet..thanks guys. I think after this project I am going to actually sit down with a VB.NET programming book and try to read it cover to cover.
 
Sweet..thanks guys. I think after this project I am going to actually sit down with a VB.NET programming book and try to read it cover to cover.

Why VB.net? Seriously. It's bad enough having to learn this shit in high school, but to actually choose it over another language when you have a choice?

I hope you have some seriously good reasons ;)
 
Why VB.net? Seriously. It's bad enough having to learn this shit in high school, but to actually choose it over another language when you have a choice?

I hope you have some seriously good reasons ;)


What language would you suggest?
 
Python or Ruby, take your pick.

Personally prefer Ruby, but accept that both are great powerful languages, that aren't too difficult for beginners to pick up.

It's really personal preference.
 
I stopped using HtmlAgilityPack a long time ago as it has some issues with parsing improperly formatted HTML, as well as a few other annoying bugs. I wrote (and used commercially for over a year) an automation client that would suit your purposes. It's freely available on GitHub here: https://github.com/axefrog/SimpleBrowser

Give it a go and let me know if you have any questions and I'll do my best to answer them.