嗨,我有一块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>
Run Code Online (Sandbox Code Playgroud)
我想获取值列表。在这种情况下,它将是“ Toltec Lighting”和“ Leaf”
您可以尝试以下方法:
//span[@id='product_description']/text()
Run Code Online (Sandbox Code Playgroud)
或者,如果您还需要确保未选择任何空文本节点,请执行以下操作:
//span[@id='product_description']/text()[normalize-space()]
Run Code Online (Sandbox Code Playgroud)