xpath 查找不包含子节点的节点 [英] xpath find node that does not contain child

查看:35
本文介绍了xpath 查找不包含子节点的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一些 xpath,它将找到所有不包含 img 标记的 a 标记,以便诸如

I'm trying to create some xpath that will find all a tags that do not contain img tags, so that something such as

<a href="http://aol.com">link</a>

匹配,但是

<a href="http://yahoo.com"><img src="http://yahoo.com/logo.png"></a>

没有.

当然,我可以通过两部分搜索来做到这一点,但我确信一定有某种方法可以用 xpath 做到这一点.

Of course I could do this in a two-part search but I'm sure there must be some way to do this with xpath.

推荐答案

//a[not(img)]

如果可以的话,尽量避免使用 //.另请注意,这只会排除 直接 包含 imgs 的 as.

Try and avoid the // if you can, though. Also note this will only exclude as that directly contain imgs.

这篇关于xpath 查找不包含子节点的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆