Xpath 使用 <br> 获取文本 [英] Xpath get text with <br>

查看:31
本文介绍了Xpath 使用 <br> 获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有 html:

<div class="offer">文本1<br>文本 2<br>文本 3<br>文本 4<br>文本5

我正在尝试使用 xpath //div[@class='offer']/text() 获取全文,但结果我有text1.
我尝试将它与 [preceding-sibling::br] 一起使用,但结果是一样的.

我需要什么?
text1 text2 text3 text4 text5

解决方案

我使用 extract() 方法修复它.

Lets say that I have html:

<div class="html">
  <div class="offer">
    text1
    <br>
    text2
    <br>
    text3
    <br>
    text4
    <br>
    text5
  </div>
</div>

Im trying to get full text with xpath //div[@class='offer']/text(), but in result I havetext1.
I try to use it with [preceding-sibling::br], but result is the same.

What I need?
text1 text2 text3 text4 text5

解决方案

I fix it using extract() method.

这篇关于Xpath 使用 &lt;br&gt; 获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆