html - 使用 xPath 在文本中查找具有特定单词的跨度
问题描述
我有很多不同文本的跨度。但是我需要在这个文本中找到一个带有某个单词的长文本的跨度。
<div class="commentMessage">
<span>Any endgame spoilers</span>
</div>
在这种情况下,我想选择一个包含带有某个单词“endgame”的文本的跨度。
这是我尝试过的:
//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')]
推荐阅读
- r - 将矩阵转换为 data.frame 给出“unclass(x)[...] 中的错误:下标越界”
- php - 如何在原始 PHP 中定义和编码自定义单元测试?
- java - 无法通过操作触发事件
- python - PRIMARY KEY 必须是唯一的
- sql - 当 order_by 列具有重复值时,order_by 在 sql 中的行为如何?
- ruby-on-rails - Rails - 如何组织常量
- swift - 如何在 tableview 页脚视图中获取复选框功能
- javascript - 如何获取 REST API 中的二级信息?
- postgresql - postgres 中的 DBCC CHECKDB 等效项
- ruby-on-rails - Rails 5.2 Active Storage 不删除附加图像