如何使用Xpath获取纯文本 [英] How to get plain text with Xpath

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

问题描述

我有这段html,我想从中获取文本元素

Hi I got this piece of html and i want to get text elements from it

<span id="product_description" itemprop="description" class="">
    <h1>Toltec Lighting 216-BRZ-508 Leaf Collection Traditional Potrack With Italian Marble Glass In Bronze</h1>
    <br class="">
    <span style="font-weight: bold;" class="">MANUFACTURE: </span>
    Toltec Lighting
    <br class=" xh-highlight">
    <span style="font-weight: bold;" class="">COLLECTION: </span>
    Leaf
    <br class=" xh-highlight">
</span>

我想获取值列表.在这种情况下,它将是"Toltec Lighting"和"Leaf"

I want to get list of values. In this case it will be "Toltec Lighting" and "Leaf"

推荐答案

您可以尝试以下方法:

//span[@id='product_description']/text()

或者如果您还需要确保未选择任何空文本节点,则:

or if you need to also make sure no empty text nodes selected :

//span[@id='product_description']/text()[normalize-space()]

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

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