XPath 从子元素中排除文本 [英] XPath Exclude Text From Child Element
本文介绍了XPath 从子元素中排除文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找输出:
50ml 牛奶
来自以下代码:
<li>50ml <a href="/glossary/milk" class="tooltip-processed">milk<div class="工具提示"></a>
目前我正在使用 XPATH:
//ul[@class="ingredients-list__group"]/li
但是得到:
50ml 牛奶 Milk mill-k 使用最广泛的成分之一,牛奶通常被称为完整的食物.虽然牛……
如何排除 div/工具提示中的内容?
解决方案
With xpath
2.0:
//ul[@class="ingredients-list__group"]/li/concat(./text()[1], ./a/text()[1])
使用 xpath
1.0:
concat(//ul[@class="ingredients-list__group"]/li/text()[1],//ul[@class="ingredients-list__group"]/li/a/text()[1])'
I'm looking to get the output:
50ml milk
From the following code:
<ul class="ingredients-list__group">
<li>50ml <a href="/glossary/milk" class="tooltip-processed">milk
<div class="tooltip">
<h2
class="node-title">Milk</h2> <span class="fonetic">mill-k</span>
<p>One of the most widely used ingredients, milk is often referred to as a complete food. While cow…</p>
</div>
</a>
</li>
</ul>
Currently I'm using the XPATH:
//ul[@class="ingredients-list__group"]/li
But getting:
50ml milk Milk mill-kOne of the most widely used ingredients, milk is often referred to as a complete food. While cow…
How do I exclude the stuff within the div/tooltip?
解决方案
With xpath
2.0:
//ul[@class="ingredients-list__group"]/li/concat(./text()[1], ./a/text()[1])
With xpath
1.0:
concat(//ul[@class="ingredients-list__group"]/li/text()[1], //ul[@class="ingredients-list__group"]/li/a/text()[1])'
这篇关于XPath 从子元素中排除文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文