BeautifulSoup - Extract text with tags as text
<p>Lets say i have the html</p>

<pre><code>&lt;div&gt;Hey&lt;/div&gt;&lt;div&gt;This is &lt;b&gt;some text&lt;b/&gt;, right here. &lt;a&gt;Link&lt;a/&gt;&lt;/div&gt;
</code></pre>

<p>and the code</p>

<pre><code>soup = BeautifulSoup(html)
texts = soup.findAll(text=True)
</code></pre>

<p>print() will return</p>

<pre><code>['Hey', 'This is ', 'some text', ', right here.', 'Link']
</code></pre>

<p>for texts.</p>

<p>How could I exclude tags like 'b' (that only contain text), so I could get the desired output which is</p>

<pre><code>['Hey', 'This is &lt;b&gt;some text&lt;b/&gt;, right here.', 'Link']
</code></pre>

<p>Also preferably <strong>not</strong> strings but equivalent NavigableStrings or similar.</p>

<p>In other words, how can I exclude some tags from navigating the tree? </p>

<p>based on updated OP's question:</p>

<pre><code>eDiv = soup.findAll("div")
if eDiv.find("b") is None:
    tag = eDiv.text
else:
    tag = eDiv
</code></pre>

<p>now you can append this into list.</p>

python beautifulsoup