I want to ask a question:
The structure is like:
<div class='item'>
<div class='all'>
BY
<p>ABC</p>
<p>DEF</p>
<p>
<span class="date">19991111</span>
</p>
</div>
</div>
I want to ask how to choose all the text()
(BY ABC DEF) but not contains <span class="date">DDD</span>
(19991111)
I found not()
method span[not(@class, 'date')
but don't know how to combine with //div[@class=item]/div[@class='all']//text()
Please teach me Thank you
You can combine them like this :
//div[@class=item]/div[@class='all']//text()[not(parent::span[@class='date'])]
Above XPath select all text nodes within the div[@class='all']
which parent is not matched by span[@class='date']
.
You may want to also filter out empty text nodes using normalize-space()
:
//div[@class=item]/div[@class='all']//text()[not(parent::span[@class='date']) and normalize-space()]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With