html - 如何使用 Xpath 获取纯文本

标签 html xpath

你好,我得到了这段 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”

最佳答案

你可以试试这个:

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

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

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

关于html - 如何使用 Xpath 获取纯文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25470623/

相关文章:

html - 可滚动的 div 移动 IE10 和 -ms-viewport

ruby - 在 Nokogiri 节点集中按类别搜索

python - 在Python中使用Selenium选择子元素

html - 为什么转换: translateX affect a fixed element's height on mobile?

java - 取消 Java 中 HTML 代码的注释

java - 如何根据提供的 HTML 从弹出窗口中定位元素?

java - 未应用last()

java - 在角度站点中使用 xpath 时找不到元素

html - 带内联 block 的交错布局,不能垂直组合框

html - 除非我做了很多换行,否则文本会卡在导航栏旁边