我正在尝试使用以下代码加载网页:
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))