尝试使用 HtmlAgilityPack 从 url 加载的非法字符异常



我正在尝试使用以下代码加载网页:

Dim DirectPage As New HtmlAgilityPack.HtmlDocument
DirectPage.Load(mUrl)

mUrl是一个字符串,包含页面的完整 URL。

网址是正确的!
我尝试将其复制/粘贴到浏览器中,它显示了正确的网页。

我也尝试了WebRequest.Create(mUrl),它奏效了。
所以我的问题是:
1)为什么HtmlAgilityPack不接受mUrl
2)什么是"非法字符"?某处有他们的清单吗?
3)有没有办法使HtmlAgilityPack代码正常工作?

这是因为HtmlAgilityPack.HtmlDocument.Load方法采用实际html而不是URL。如果要加载页面,请使用HtmlWeb.Load(url)

另一种选择

 Dim wC As New WebClient() 
 DirectPage.Load(wC.OpenRead(mUrl))

相关内容

最新更新