Hap*_*ird 6 html xml xpath ends-with
鉴于HTML包含:
<div tagname="779853cd-355b-4242-8399-dc15f95b3276_Destination" class="panel panel-default"></div>
Run Code Online (Sandbox Code Playgroud)
我们如何在XPath中编写以下表达式:
查找属性以字符串'Destination'结尾的<div>
元素tagname
我一直在寻找几天,我无法想出一些有用的东西.在众多中,我试过例如:
div[contains(@tagname, 'Destination')]
Run Code Online (Sandbox Code Playgroud)
//div[ends-with(@tagname, 'Destination')]
Run Code Online (Sandbox Code Playgroud)
//div[substring(@tagname,string-length(@tagname) -string-length('Destination') +1)
= 'Destination']
Run Code Online (Sandbox Code Playgroud)
您可以使用ends-with
(Xpath 2.0)
//div[ends-with(@tagname, 'Destination')]
Run Code Online (Sandbox Code Playgroud)
XPath 2 或 3:总是有正则表达式。
.//div[matches(@tagname,".*_Destination$")]
Run Code Online (Sandbox Code Playgroud)