需要找到与任何html标记中包含单词sidebar的html标记匹配的xpath。示例:
<p class='my class'>This is some text</p>
<h1 class='btn sidebar btn-now'><p>We have more text here</p><p> and anoter text here</p></div>
<div id='something here'>New text here</div>
<div id='something sidebar here'>New text again</div>
<nav class='this sidebar btn'>This is my nav</nav>
<sidebar><div>This is some text</div></sidebar>
我需要xpath来获取任何在<和结束> html标签之间具有单词“ sidebar”的html元素,无论是类,id还是html标签名称。在上面的示例中,我需要得到结果:
<h1 class='btn sidebar btn-now'><p>We have more text here</p><p> and anoter text here</p></div>
<div id='something sidebar here'>New text again</div>
<nav class='this sidebar btn'>This is my nav</nav>
<sidebar><div>This is some text</div></sidebar>
需要是xpath而不是正则表达式
答案 0 :(得分:2)
尝试以下方法,如果不是您要搜索的内容,请告诉我:
//*[contains(@*, "sidebar") or contains(name(), "sidebar")]
contains(@*, "sidebar")
表示具有任何属性且包含"sidebar"
contains(name(), "sidebar")
-包含"sidebar"
如果只需要id
或class
来包含"sidebar"
:
//*[contains(@id, "sidebar") or contains(@class, "sidebar") or contains(name(), "sidebar")]