正如标题所说,是否可以在 XPath 中选择仅以某个字符串开头但可能不以相同结尾的元素?
例如有 3 个 anchor 元素:
<a href="buy.php/onething"></a><a href="buy.php/twothing"></a><a href="sell.php/anotherthing"></a>
我只想获取以“buy.php/”开头的 anchor 元素。我认为以下方法行不通,对吗:
getByXPath("//a[@href='buy.php/']")
我该怎么做?
最佳答案
//a[starts-with(@href, 'buy.php/')]
http://www.zvon.org/xxl/XSLTreference/Output/function_starts-with.html
关于java - 选择属性以 XPath 中的某些内容开头的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3301898/