xpath - 具有以下特定兄弟情况的 XPath
问题描述
我的结构看起来像这样
<p>
<br>
<b>Text to fetch </b>
<br>
"Some random text"
<b>Text not to fetch</b>
我需要 XPath,只有当br元素和他的下一个兄弟元素之间没有文本时,我才能获取br元素的下一个兄弟元素。
如果我做这样的事情
//br/following-sibling::b/text()[1]
它会同时获取Text to fetch
and Text not to fetch
,而我只需要Text to fetch
.
解决方案
尝试使用 XPath 来避免将b
节点与前面的同级文本匹配:
//br/following-sibling::b[not(preceding-sibling::text()[1][normalize-space()])]/text()
推荐阅读
- intershop - 7.9 中自定义 URLRewrite 规则的问题
- angular - Ionic Web 版本处理禁用元素
- javascript - ERROR 错误:ENOENT:没有这样的文件或目录,在节点 js 中创建文本文件时打开
- sass - CSS 以一种看起来不正确的方式编译 lighten() 函数和类似的 SASS 颜色函数
- azure - 使用 PATH 对 SQL API 中的数据进行 Azure Cosmos DB 分区和索引
- ios - 如何使用 Swift 4 从 CMSampleBuffer 创建数据
- javascript - Service Worker 范围和 SPA 导航
- java - 对 Java 中的引用感到困惑
- reactjs - 将样式表导入组件 vs SMACSS 方法
- node.js - 使用 node.js 和 Glob 将多个文件从 Google Cloud VM 上传到 Google Cloud Storage