Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
xpath无法返回html文档的开头_Html_Asp.net_Xpath_Html Agility Pack - Fatal编程技术网

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可以访问它,并最终呈现
。或者简单地调整选择器:HtmlNode
HtmlNode=htmlDocument.DocumentNode.SelectSingleNode(“head”)。好的,那么如何处理这种差异。因为我必须阅读随机页面,我无法猜测每页文档的结构。
htmlDocument.DocumentNode.SelectSingleNode(“head”)。或无法为每个浏览器执行此操作,因为这取决于用户希望使用哪个浏览器。。