html - 获取文本部分到 xpath 中的特定标签
问题描述
我正在尝试使用 Xpath 获取文本直到第一个 <.hr>(ignore dot) 标记
<div class="entry">
<p> some text</p>
<p> some text2</p>
<p> some text3</p>
<p> some text4</p>
<hr>(get text part before this hr tag)
<p> some text5</p>
<hr>
<p> some text6</p>
</div>
试过这个
//hr[1]/ancestor::div[@class="entry"]/text()
和一些类似的变体,但无法获得预期的输出
解决方案
沿着这些线的东西会给你节点之前的hr
节点集
//div[@class="entry"]/*[not(preceding-sibling::hr | self::hr)]
它将列出那些节点
- 是类名为“entry”的 div 的子项,
- 前面没有名为 hr 的节点和
- 本身不是
hr
节点
推荐阅读
- java - 是否可以使用 Swagger codegen 在多个目录中生成模型?
- grails - GORM 独立使用 Domain.findBy[property] 的问题
- architecture - 需要关于使用哪种方法进行信息亭软件开发的建议
- android - Android Studio does not recognise androidx preference library in xml
- java - android.database.sqlite.SQLiteException:靠近“UNION”:语法错误
- java - How can I disable Java EE interceptor on application start up, for example by condition from database logger=info?
- c++ - CMake - 为生成的项目定义 dll 目录或文件
- sql - 每个日期只选择一个具有 MAX(Id) 的产品
- java - Unable to load OracleDriver in a Grails application
- deployment - Do I need composer on TYPO3 production-system when my TYPO3 is in composer mode