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
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.
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
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?