Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.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
C# xpath问题(HtmlAgilityPack)_C#_Html_Xpath_Html Parsing - Fatal编程技术网

C# xpath问题(HtmlAgilityPack)

C# xpath问题(HtmlAgilityPack),c#,html,xpath,html-parsing,C#,Html,Xpath,Html Parsing,我有一个“TR”节点数组。我只想得到每个元素的子“TD”标记 我不知道怎么做。 有人知道吗 这是我的密码: foreach (HtmlNode tr in doc.DocumentNode.SelectNodes("//table[@id=\"ctl00_ContentPlaceHolder1_CustomerByLocation_ViewPanelStandAlone_ViewPanel_Grid_ctl01\"]/tr[position()>1]")) { foreach (H

我有一个“TR”节点数组。我只想得到每个元素的子“TD”标记

我不知道怎么做。 有人知道吗

这是我的密码:

foreach (HtmlNode tr in doc.DocumentNode.SelectNodes("//table[@id=\"ctl00_ContentPlaceHolder1_CustomerByLocation_ViewPanelStandAlone_ViewPanel_Grid_ctl01\"]/tr[position()>1]"))
{
    foreach (HtmlNode td in tr.SelectNodes("//td"))
    {
         w.WriteLine(td.InnerHtml);
    }
    w.WriteLine("***********************");
}
在XPath中“/”表示“所有节点都从根开始-因此第二次搜索
”//td“
忽略
tr
作为父节点,并搜索整个DOM


很可能您只是在寻找
“td”
(而不是
“//td”
).

不确定这是否能解决问题,但在字符串中使用单引号。我一直都是这样做的。@Alexerrmann您需要使用单引号。。还要检查
id
值是否与html@AlexHerrmann,并不是每种语言都像C/C++/Java那样使用单引号,我90%确信XPath不遵循C约定这是一个过于宽泛的陈述。是的,你是对的。这肯定是关于xpath的。不。第二个//td不会搜索整个dom@Anirudh-你认为这意味着什么?