How to get plain text with Xpath

£可爱£侵袭症+ 提交于 2021-02-05 06:25:06

问题


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>

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


回答1:


You can try this :

//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()]



回答2:


You may try using this:

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


来源:https://stackoverflow.com/questions/25470623/how-to-get-plain-text-with-xpath

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!