【发布时间】:2020-08-26 23:36:05
【问题描述】:
鉴于此 html 示例:
<div class="measure-tab"> --- i want to select this one
<span class="color_title">someText</span>
</div>
<div class="measure-tab"> --- i dont want to select this one
<span class="color_title">someText</span>
<div>
<span class="qwery">jokerText</span>
</div>
</div>
<div class="measure-tab"> --- i want to select this one
<span class="color_title">someText</span>
</div>
我想选择具有 @class='measure-tab' 的 div,它下面有一个作为特定类和 text = someText 的跨度和一个具有特定类但不包含 text = ' 的嵌套跨度jokerText',所有这些都在 XPATH 中
我试过的是:
//div[contains(@class, 'measure-tab') and //span[@class="color_title" and (contains(text(),'someText')) and //span[@class="color_title" and not(contains(text(),'jokerText'))]]
但这似乎不起作用。 我还使用This 帖子作为灵感。
编辑:更正了对该问题目标的错误描述
编辑,提出了一个新的解决方案:
//div[contains(@class, 'measure-tab') and //span[contains(@class, 'color_title') and //span[not(contains(@class, 'qwery'))]]]
但这会返回所有 div,而不是不匹配 --- 我不想选择这个
<span class="color_title">someText</span>
<div>
<span class="qwery">jokerText</span>
</div>
我感觉如此接近,但到目前为止,哈哈,这对我来说没有意义,为什么当我写的时候它与<span class="qwery">jokerText</span> 匹配不包含那里
【问题讨论】:
-
以下答案是否解决了您的问题?如果是,请随时点击图标
√接受正确答案