【问题标题】:How to get plain text with Xpath如何使用 Xpath 获取纯文本
【发布时间】:2021-02-18 11:19:59
【问题描述】:

嗨,我得到了这段 html,我想从中获取文本元素

<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”

【问题讨论】:

    标签: html xpath


    【解决方案1】:

    你可以试试这个:

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

    或者如果您还需要确保没有选择空文本节点:

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

    【讨论】:

    • 我也想包含文本值。我怎么能做到这一点?下面一个有效吗? //span[@id='product_description']/text()['COLLECTION: ']
    【解决方案2】:

    你可以试试这个:

    //*[text()='Toltec Lighting']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-07
      • 1970-01-01
      • 2019-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-08
      相关资源
      最近更新 更多