python - Python - Selenium Xpath 在第一个和第二个 h3 标签之间获取内容
问题描述
结构:
<h3>Description</h3>
<p>Para1</p>
<p>Para1</p>
<p>Para1</p>
<p>Para1</p>
<h3>Description2</h3>
<p>Para1</p>
<p>Para1</p>
<p>Para1</p>
<p>Para1</p>
现在我想提取<p>
first<h3>
到 second之间的所有内容<h3>
。
条件:
- 不使用标题内容检查。由于 Description2
<h3>
是动态内容,而不是恒定值。 <h3>
有时会<h1>
或<h2>
太...
尝试下面的通用代码,
One way
$x("//*[starts-with(name(),'h')][starts-with(.,'Description')]/following-sibling::*[following-sibling::*[starts-with(name(),'h')][starts-with(.,'Description2')]]")
Another
$x("//*[preceding-sibling::*[starts-with(name(),'h')] = 'Description' and following-sibling::*[starts-with(name(),'h')] = 'Description2']")
如何在不指定 Description & Description2 文本的情况下在内容之间进行查询?
解决方案
推荐阅读
- arrays - 循环遍历 node/jade 中的类似键
- sql - 尝试使用 PostgreSQL 将数据加载到表中?
- firebase - 类型“{}”rxjs6 上不存在属性“地图”
- api - Telegram bot api:sendPhoto 不呈现 html
- java - 如果按钮在另一个 div 中,如何单击 htmlUnit
- android - onStartCommand() 中的 IllegalStateException
- python - python:从字典中获取值并将其作为键插入另一个字典
- php - 如何基于同一列单元格输出一个组,同时将其循环到 html 中?
- css - CSS - form_for 中“.....”的选择器
- idris - 如何证明 ((x :: xs) = (y :: ys)) 给定 (x = y) & (xs = ys)