xpath无法返回html文档的开头
我正在尝试阅读此链接xpath无法返回html文档的开头,html,asp.net,xpath,html-agility-pack,Html,Asp.net,Xpath,Html Agility Pack,我正在尝试阅读此链接http://www.aspemail.com带有HtmlAtiligtyPack。但它无法读取head部分的值并返回null HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlDocument(); System.Net.WebClient webClient = new System.Net.WebClient(); string download = webClient.Do
http://www.aspemail.com
带有HtmlAtiligtyPack
。但它无法读取head部分的值并返回null
HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlDocument();
System.Net.WebClient webClient = new System.Net.WebClient();
string download = webClient.DownloadString(linkDetails.Url);
htmlDocument.LoadHtml(download);
HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("html/head");
但是当我检查放置的断点时,htmlNode包含null。我使用的这个程序可以吗
SelectSingleNode("html/head");
你看过这个网站的来源了吗?其中没有
节点。结尾处只有一个结尾,但是源代码直接以一个开头,天哪,现在是什么样的人在写网站真是不可思议
您可以这样调整选择器:
HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("head");
我用opera检查过,里面有html节点。我用Google Chrome检查过,没有
。由于您使用的是WebClient,并且没有指定用户代理
请求头,因此我猜该站点不会返回
。一种可能是发送opera的用户代理,诱使站点认为opera可以访问它,并最终呈现
。或者简单地调整选择器:HtmlNodeHtmlNode=htmlDocument.DocumentNode.SelectSingleNode(“head”)代码>。好的,那么如何处理这种差异。因为我必须阅读随机页面,我无法猜测每页文档的结构。htmlDocument.DocumentNode.SelectSingleNode(“head”)代码>。或无法为每个浏览器执行此操作,因为这取决于用户希望使用哪个浏览器。。