How to get all direct children of a BeautifulSoup Tag? : <p>How to retrieve (not recursively) all children using BeautifulSoup (bs4) ?</p>

<p><code>&lt;div class='body'&gt;&lt;span&gt;A&lt;/span&gt;&lt;span&gt;&lt;span&gt;B&lt;/span&gt;&lt;/span&gt;&lt;span&gt;C&lt;/span&gt;&lt;/div&gt;</code></p>

<p>I want to get blocks like this : </p>

<pre><code>block1 : &lt;span&gt;A&lt;/span&gt;
block2 : &lt;span&gt;&lt;span&gt;B&lt;/span&gt;&lt;/span&gt;
block3 : &lt;span&gt;C&lt;/span&gt;
</code></pre>

<p>I'm doing this way :</p>

<pre><code>for j in soup.find_all(True)[:1]:
            if isinstance(j, NavigableString):
                continue
            if isinstance(j, Tag):
                tags.append(j.name)
                # Get siblings
                for k in j.find_next_siblings():
                    # k is sibling of first element
</code></pre>

<p>Is there a cleaner way to do that?</p>
