Reputation: 33847
With XPath, how to select all the images that are not inside <a>
tag?
For example, here:
<a href='foo'> <img src='bar'/> </a>
<img src='ham' />
I should get "ham"
image as a result. To get the first image, I would use \\a\\img
. Is there anything like \\not(a)\\img
?
I use python + lxml so python hacks are welcome, if pure xpath would be to hairy.
Upvotes: 0
Views: 163
Reputation: 338316
That's easily done with
//img[not(ancestor::a)]
Read the spec on XPath axes if you want to find out about the other ones besides ancestor
.
Upvotes: 4