【发布时间】:2018-09-09 09:19:41
【问题描述】:
需要找到与任何 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 而不是正则表达式
【问题讨论】:
-
是否也能找到
<a href="sidebar">、<div data-sidebar="foo">、<p class="sideb&#97;r">? -
@melpomene 是的,html 标签里面有侧边栏
-
最后一个的 HTML 代码中没有
sidebar。 -
标签(不是有效的 html 标签,仅作为示例)但基本上如果它存在,那么 和 之间的所有内容都应该匹配。如果您认为那里不正常,我可以从上面的示例中删除它 -
我说的是我的例子,不是你的。
<p class="sideb&#97;r">不包含sidebar。你希望它被发现还是不被发现?
标签: xpath