How to find element with specific parent?
<p>I have some HTML like:</p>

<pre><code>&lt;div class='cl1'&gt;
    &lt;div class='cl2'&gt;text_1&lt;/div&gt;
    &lt;div class='cl3'&gt;
        &lt;div class='cl2'&gt;text_2&lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>I need to find any items of cl2 class that have cl1 as parent, so i need to get <strong>text_1</strong> but not <strong>text_2</strong>. In simple css it should be like this:</p>

<pre><code>'div.cl1&gt;div.cl2'
</code></pre>

<p>but I use <em>robobrowser</em> and <em>BeautifulSoup</em>, and when I try</p>

<pre><code>soup.select('div.cl1&gt;div.cl2')
</code></pre>

<p>it says that css selector is wrong.</p>

<p>One possible solution would be:</p>

<pre><code>from bs4 import BeautifulSoup
data = """
&lt;div class='cl1'&gt;
    &lt;div class='cl2'&gt;text_1&lt;/div&gt;
    &lt;div class='cl3'&gt;
        &lt;div class='cl2'&gt;text_2&lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
"""
soup = BeautifulSoup(data)
divs = [div
        for div in soup.find_all("div", {'class': 'cl2'})
        if 'cl1' in div.parent["class"]]

# [&lt;div class="cl2"&gt;text_1&lt;/div&gt;]
</code></pre>

python css-selectors beautifulsoup robobrowser