Xpath有一个无效的令牌

时间:2017-05-22 16:11:25

标签: c# xml xpath

我希望在带有xpath的“ac-algo fz-l ac-21th lh-24”类名的html页面中获取所有链接。

我写了代码:

SELECT *
FROM dbo.YourTable A
WHERE EXISTS(SELECT 1 FROM dbo.YourTable 
             WHERE DepartmentNumber = A.DepartmentNumber
             GROUP BY DepartmentNumber
             HAVING COUNT(*) > 1) 
AND ID = ManagerID;


但我得到这个错误:

string links = node.SelectSingleNode(".//a[(@class,'ac-algo fz-l ac-21th lh-24')]").GetAttributeValue("href", null);

1 个答案:

答案 0 :(得分:2)

用等号替换逗号并删除下面的括号,以便按照确切的类名匹配元素:

string links = node.SelectSingleNode(".//a[@class='ac-algo fz-l ac-21th lh-24']").GetAttributeValue("href", null);

或者您可以使用contains()按部分类名匹配元素:

string links = node.SelectSingleNode(".//a[contains(@class,'ac-algo fz-l ac-21th lh-24')]").GetAttributeValue("href", null);