我有很多不同文本的 span。但是我需要找到一个带有长文本的跨度,其中包含该文本中的某个单词。
<div class="commentMessage">
<span>Any endgame spoilers</span>
</div>
在这种情况下,我想选择一个包含带有特定单词“残局”的文本的跨度。
这是我尝试过的:
//div[@class='commentMessage']/span[text()='endgame'] - but it show no results (very strange) =\
然后我尝试使用所有短语找到跨度:
//div[@class='commentMessage']/span[text()='Any endgame spoilers'] - and it works =\
但正如我所说,我需要找到一个使用特定单词的跨度。
此外,我尝试了这种构造:
//div[@class='commentMessage']/span[contains(text(), 'endgame')] - but Chrome xPath extension says: Type is not appropriate for the context in which the expression occurs
最佳答案
尝试以下 xpath。
//div[@class='commentMessage']/span[contains(.,'endgame')]
关于html - 使用 xPath 在文本中查找具有特定单词的跨度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56062050/