How to extract certain data while filtering out the ones including colspan?
<p>For example:</p>

<pre><code>&lt;tbody&gt;
&lt;tr&gt;&lt;td colspan="2"&gt;&lt;p&gt;Unwanted Text 1&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;a href="http://www.example.com"&gt;Text 1&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Nonesense 1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;a href="http://www.example2.com"&gt;Text 2&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Nonesense2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan="2"&gt;&lt;p class="second-title"&gt;Unwanted Text 1&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
</code></pre>

<p>I tried: </p>

<pre><code>soup.select('tr')
for x in g:
    print(x.contents[0].text)
</code></pre>

<p>Output:</p>

<pre><code>Unwanted Text 1
Text 1
Text 2
Unwanted Text 2
</code></pre>

<p>How can I only get "Text 1" and "Text 2" while omitting the other ones.</p>

<p>You can match the <code>a</code> elements directly:</p>

<pre><code>for item in soup.select('tr &gt; td &gt; a'):
    print(item.get_text())
</code></pre>

<p>Or, if you specifically want to skip rows with <code>td</code> elements having <code>colspan</code> attributes:</p>

<pre><code>for item in soup.select('tr'):
    if item.find("td", colspan=True):
        continue
    print(item.td.get_text())  # get text of the first cell in the row
</code></pre>

python web-scraping beautifulsoup