XPath / HTMLAgilityPack问题

| 我想从这里获取球员名单: http://www.basketball-reference.com/boxscores/201105090BOS.html 为此,请使用以下表格:
HtmlNode reboundsNode = doc.DocumentNode.SelectSingleNode(\"//table[@class=\'sortable stats_table\']/tbody[1]\");
    foreach(HtmlNode node in reboundsNode.SelectNodes(\"tr\"))
    {
        // Get the \'td\'s.
    }
我不得不将其分为两行,因为
\"//table[@class=\'sortable stats_table\']/tbody[1]/tr\"
从所有表主体中选择了
tr
,而不仅仅是第一个。有人知道为什么吗? 从第二个表中获取数据时,我也遇到了问题(实际上是源中的表号3,因为在默认视图中有不可见的表2和4)。当我选择
\"//table[@class=\'sortable stats_table\']\"
时,它表明有四个表,但是当我选择
\"//table[@class=\'sortable stats_table\'][3]\"
时,它什么也没找到(尝试使用结果时出现未绑定对象异常。为什么?     
已邀请:
        因为XPath []不是表主体的数目,而是condition,所以1表示始终为true-尝试执行此操作-它将从第一个tbody中进行选择
 //table[@class=\'sortable stats_table\']/tbody[position() = 1]/tr
第二个问题
 //table[@class=\'sortable stats_table\'][3]
这是无效的xpath-正确的写法是
 //table[@class=\'sortable stats_table\' and position() = 3]
注意:位置从1开始而不是从0开始,并以元素计数结束。     

要回复问题请先登录注册