Results 1 to 4 of 4

Thread: HtmlAgilityPack - getting error when looping through nodes. Doesn't make sense

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2011
    Posts
    7

    HtmlAgilityPack - getting error when looping through nodes. Doesn't make sense

    I'm trying to get all nodes below but I am getting an error message of:

    Overload resolution failed because no accessible 'GetAttributeValue' accepts this number of arguments.

    Code:
    Dim nodes As HtmlNodeCollection = docNode.SelectNodes("//input | //select | //textarea")
    
    For Each node As HtmlNode In nodes
    
    Dim id As String = node.GetAttributeValue("id")
    
    Next
    Any ideas on why I am getting this error message? Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: HtmlAgilityPack - getting error when looping through nodes. Doesn't make sense

    It makes perfect sense and it means exactly what it says. The GetAttributeValue method is overloaded. It has three overloads and all three of them have two parameters, so you can't call it and pass a single argument. Intellisense would have told you what parameters the method had when you wrote the code so you should pay attention to those informational messages.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2011
    Posts
    7

    Re: HtmlAgilityPack - getting error when looping through nodes. Doesn't make sense

    Ahh...i see..cool thanks bro!....here is my code.

    Code:
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim doc As New HtmlDocument()
            doc.LoadHtml("http://www.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
                Dim id As String = node.GetAttributeValue("id", "value")
                ' Fetch id of HTML element
                Dim name As String = node.GetAttributeValue("name", "value")
                ' Fetch parameter name (GET/POST)
                ' Fetch type of input element
                ' Do your processing now
                
                Form2.RichTextBox1.Text = id.ToString & name.ToString
    
    
            Next
    
    
    
    
        End Sub

    I am now getting a new error of NullReferenceException was unhandled

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: HtmlAgilityPack - getting error when looping through nodes. Doesn't make sense

    Which line is the exception thrown on? What reference on that line is null?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width