Pass string of HTML page and scrape with HtmlAgilityPack

c# html-agility-pack vb.net

Question

I got this error, why?

"Illegal characters in path" at htmlDoc.Load(pageSource)

pageSource is an HTML page string variable. Not as a file or a URL, but as a string, I must supply the page source. What should I do?

Dim ids As New List(Of String)()
Dim pageSource = getHtml(url)

Dim htmlDoc As HtmlDocument = New HtmlDocument()

htmlDoc.OptionFixNestedTags = True


htmlDoc.Load(pageSource)


Dim s As HtmlNodeCollection = htmlDoc.DocumentNode.SelectNodes("//div/@id")

For Each div As HtmlNode In s
    ids.Add(div.Id)
Next
1
1
3/12/2013 3:42:07 PM

Accepted Answer

Use LoadHtml in place ofLoad :

htmlDoc.LoadHtml(pageSource)

See the source as well.

9
7/21/2012 4:51:33 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow