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

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

问题描述

我正在尝试创建一些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)]

请尝试并尽量避免使用//.另请注意,这将仅排除直接 包含imga.

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

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

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