我正在使用 HtmlAgilityPack 从网页中抓取表格。
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load("http://test.com");
我知道 HtmlWeb 有一个 UserAgent 属性,但是我不知道我应该如何将用户代理附加到 httprequest 的 header 。
HtmlWeb web = new HtmlWeb().UserAgent("asdf");
返回错误
Error 1 Non-invocable member 'HtmlAgilityPack.HtmlWeb.UserAgent' cannot be used like a method.
http://htmlagilitypack.codeplex.com/discussions HtmlAgilityPack 支持讨论显示为简单的问题,但另一端没有人回应。
http://htmlagilitypack.codeplex.com/documentation这里还没有文档。
http://htmlagilitypack.codeplex.com/downloads/get/437942尝试下载文档,发现 chm 文件似乎已损坏...当我尝试打开 chm 文档中的任何内容时,出现网页导航被取消错误。
请您参考如下方法:
实例化HtmlWeb对象后,只需设置UserAgent属性即可。
HtmlWeb web = new HtmlWeb();
web.UserAgent = "your useragent string here";
