XPath 查找没有 id 或 class 的元素 [英] XPath to find elements that does not have an id or class

查看:81
本文介绍了XPath 查找没有 id 或 class 的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取所有没有 id 属性的 tr 元素?

How can I get all tr elements without id attribute?

<tr id="name">...</tr>
<tr>...</tr>
<tr>...</tr>

谢谢

推荐答案

非常简单:

//tr[not(@id) and not(@class)]

这将为您提供缺少 idclass 属性的所有 tr 元素.如果您希望所有 tr 元素都缺少两者之一,请使用 or 而不是 and:

That will give you all tr elements lacking both id and class attributes. If you want all tr elements lacking one of the two, use or instead of and:

//tr[not(@id) or not(@class)]

以这种方式使用属性和元素时,如果属性或元素具有值,则将其视为真值.如果丢失,则将其视为假.

When attributes and elements are used in this way, if the attribute or element has a value it is treated as if it's true. If it is missing it is treated as if it's false.

这篇关于XPath 查找没有 id 或 class 的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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