属性值中的 XPath 通配符
我有以下 XPath 来匹配类跨度的属性:
//span[@class='amount']
我想匹配具有“amount”类属性但也可能具有其他类的所有元素。我以为我可以做到这一点:
//span[@class='*amount*']
但这不起作用......我该怎么做?
I have the following XPath to match attributes of the class span:
//span[@class='amount']
I want to match all elements that have the class attribute of "amount" but also may have other classes as well. I thought I could do this:
//span[@class='*amount*']
but that doesn't work...how can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用以下表达式:
您可以单独使用
contains
,但这也可以匹配someamount
等类。在以下输入上测试上述表达式:它将选择前四个
span
元素,但不会选择最后一个。Use the following expression:
You could use
contains
on its own, but that would also match classes likesomeamount
. Test the above expression on the following input:It will select the first four
span
elements, but not the last one.您需要使用 contains 方法。请参阅如何在此处使用 XPath contains()?
//span [包含(@class,'金额')]
You need to use contains method. See How to use XPath contains() here?
//span[contains(@class,'amount')]