Exclude Item from Web-Scraped Loop
<p>Suppose I have the following <code>html</code>:</p>

<pre><code>&lt;h4&gt;
     &lt;a href="http://www.google.com"&gt;Google&lt;/a&gt;
&lt;/h4&gt;
&lt;h4&gt;Random Text&lt;/h4&gt;
</code></pre>

<p>I am able to identify all <code>h4</code> headings via a loop such as:</p>

<pre><code>for url in soup.findAll("h4")
    print(url.get_text())
</code></pre>

<p>And that works well except it includes the "random text" element of the <code>h4</code> heading.  Is it possible to programmatically remove occurrences of <code>h4</code> headings that do not meet a certain criteria - for example, those that don't contain a link?</p>

<p>Use list comprehension as the most pythonic approach:</p>

<pre><code>[i.get_text() for i in soup.findAll("h4") if #Insert criteria here#]
</code></pre>

python web-scraping beautifulsoup