Find all the 'h2' tags that are children of a specific div with attribute 'id' and value 'column-left'
<p>Using BeautifulSoup, I tried the following:</p>

<pre><code>q =  soup.div.find_all("div", { "id" : "column-left" }, "h2")
</code></pre>

<p>But this gives me the text of the <code>&lt;p&gt;</code> as well. I just want the h2 that are children of a specific div.</p>

<p>If you use a recent version of BeautifulSoup (and you should) you can just use a CSS selector, which might be easier to write and maintain anyway. e.g.:</p>

<pre><code>&gt;&gt;&gt; from bs4 import beautifulsoup
&gt;&gt;&gt; soup = BeautifulSoup('&lt;div id=column-left&gt;&lt;h2&gt;Header&lt;/h2&gt;&lt;p&gt;Paragraph&lt;/p&gt;&lt;h2&gt;Another header&lt;/h2&gt;&lt;p&gt;Another paragraph&lt;/p&gt;&lt;/div&gt;')
&gt;&gt;&gt; soup.select('div#column-left &gt; h2')
[&lt;h2&gt;Header&lt;/h2&gt;, &lt;h2&gt;Another header&lt;/h2&gt;]
</code></pre>

python web-scraping beautifulsoup