使用css选择器查​​找标记,但不是其后代 [英] Find tags using css selector but not their descendants

查看:157
本文介绍了使用css选择器查​​找标记,但不是其后代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到符合某些条件但只是第一级(相对)(而不是等)的标签。我不想找到符合条件的他们的子女孙子等。可能吗?

I'm trying to find tags meeting some condition but just those on the first level (relatively) (not their children etc.). I don't want to find their children, grandchildren etc. whose meeting the condition. Is it possible?

我使用 Selenium Python

<div id="example1">
    <div id="example2">
    </div>
</div>
<div id="example3">
</div>

我想返回 example1 example3 (不 example2 )。

c> div 可以是 body 的子类,但也可以是孙子等等。 driver.find_element_by_css_selector

Those divs can be a children of a body but they can be also grandchildren etc. so driver.find_element_by_css_selector(body > div[name*=example]) is not enough.

推荐答案

这样的东西可以做的诀窍:

Something like this could do the trick:

*:not([id*=example]) > [id*=example]

http://codepen.io/anon/pen/EVxYjE

这篇关于使用css选择器查​​找标记,但不是其后代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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