Chris Wheelous
Chris Wheelous

Reputation: 75

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.

Dim doc As New HtmlDocument() 
doc.LoadHtml("shaggybevo.com/board/register.php") 
Dim docNode As HtmlNode = doc.DocumentNode 
Dim nodes As HtmlNodeCollection = docNode.SelectNodes("//input")

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

Upvotes: 1

Views: 579

Answers (1)

competent_tech
competent_tech

Reputation: 44931

You need to provide a default value as a second parameter to GetAttributeValue:

Dim id As String = node.GetAttributeValue("id", "")

Update for updated question

In addition to the above fix, you are retrieving the HtmlDocument incorrectly. HtmlDocument.Load will either load a file or an HTML string, not retrieve the file from the web server.

You need to modify your code to fetch the data from the URL using HtmlWeb. Replace the following lines:

Dim doc As New HtmlDocument() 
doc.LoadHtml("shaggybevo.com/board/register.php") 

with these:

Dim doc As HtmlDocument
Dim web As New HtmlWeb

doc = web.Load("http://shaggybevo.com/board/register.php")

Upvotes: 0

Related Questions