![](/img/trans.png)
[英]How to select all children text but excluding a tag with Scapy's XPath?
[英]How to select all text excluding a single node using XPath?
给定以下XML:
<div class="a">
some text i want to see
<div class="b">
other text i want to see
<div>
<div class="c">
some text i DON'T WANT to see
</div>
some more text i wish to see..
</div>
我希望有一个XPATH可以选择所有不在类c
下的文本。
预期产量:
some text i want to see
other text i want to see
some more text i wish to see..
这个XPath
//div[@class="a"]//text()[not(parent::div[@class="c"])]
将选择所有没有@class="c"
的div
父节点的文本节点:
some text i want to see
other text i want to see
some more text i wish to see..
如果您要排除纯空格文本节点,请使用此XPath,
//div[@class="a"]//text()[not(parent::div[@class="c"]) and normalize-space()]
将选择这些文本节点,
some text i want to see
other text i want to see
some more text i wish to see..
按照要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.