html - 如何根据跨度内的文本获取跨度的以下元素
问题描述
如何使用跨度内的文本识别跨度的以下元素。在下面的代码中,我需要使用其文本识别第一个跨度以在<li>
. 我可以使用它的类属性来识别跨度,但我不能用它contains(text(), 'System stopped operation')
来识别跨度标签。我的想法是使用其类识别第一个跨度,然后找到以下内容<li>
<span class="text-danger">
<img src="images/crit.gif" width="15" height="15" border="0" align="absbottom" alt="Critical Alarm" title="Critical Alarm">
System stopped operation
</span>
<ul>
<li>
The system is not in operation.</li>
</ul>
<span class="text-warning">
<img src="images/warn.gif" width="15" height="15" border="0"
align="absbottom" alt="Warning Alarm" title="Warning Alarm">
System restarted
</span>
<ul>
<li>
System has been restarted.</li>
</ul>
解决方案
<li>
要根据相应标签中的文本识别元素<span>
,可以使用以下基于xpath的解决方案:
将
<li>
带有文本的标识为系统未运行://span[contains(., 'System stopped operation')]//following::ul[1]/li
要将
<li>
with 文本标识为System has been restarted://span[contains(., 'System restarted')]//following::ul[1]/li
推荐阅读
- javascript - 为什么 RxDB 的 vanilla JS 示例不起作用
- javascript - 将数字字符串转换为数字数组?
- android - 合成 TextToSpeech - 合成文本后文件不立即可用
- python-3.x - Jupyter Notebook 存在连接问题。在这一点上感到绝望,因为没有任何工作
- r - RTextTool包中的train_model函数问题,溢出错误
- reactjs - NextJS 静态构建将文件引用到 C://?
- google-cloud-platform - 如何从该数据流作业中获取数据流作业 ID - JAVA
- java - java.lang.NullPointerException null 对象引用 viewpager
- sql-server - 用于正确排序带有表情符号的 nvarchar 字段的 MSSQL 排序规则
- c# - 在运行时转换为未知的派生类型?