Extracting text within tag with BeautifulSoup
<pre><code>    &lt;div&gt;
&lt;p class="tabbed" style="margin-top:2px;"&gt;&lt;span class="tab"&gt;&lt;strong&gt;LANGUAGES&lt;/strong&gt;&lt;/span&gt;Cantonese&lt;/p&gt;
&lt;p class="tabbed" style="margin-top:2px;"&gt;&lt;span class="tab"&gt;&lt;/span&gt;English&lt;/p&gt;
&lt;p class="tabbed" style="margin-top:2px;"&gt;&lt;span class="tab"&gt;&lt;/span&gt;Putonghua&lt;/p&gt;
&lt;p class="tabbed"&gt;&lt;span class="tab"&gt;&lt;strong&gt;GENDER&lt;/strong&gt;&lt;/span&gt;Male&lt;/p&gt;
   &lt;/div&gt;
</code></pre>

<p>I would like to extract the "Male" in the 5th line but I don't know how to do it. Can anyone help? 
I tried " gen = soup.find('span', class_='tab').string" but it doesn't work. </p>

<p>You can use the <a href="https://www.google.co.in/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=0ahUKEwja4Ii7q_fOAhVGN48KHR_QDZsQygQIHzAA&amp;url=https%3A%2F%2Fwww.crummy.com%2Fsoftware%2FBeautifulSoup%2Fdocumentation.html%23The%2520basic%2520find%2520method%3A%2520findAll(name%2C%2520attrs%2C%2520recursive%2C%2520text%2C%2520limit%2C%2520**kwargs)&amp;usg=AFQjCNFvmAXY4S9WJwdCGla7HED-zGam4A&amp;sig2=-fvqI2tGt02bZk6ckYAqaA&amp;bvm=bv.131783435,d.c2I" rel="nofollow">.findAll()</a> method:</p>

<pre><code>In [37]: from bs4 import BeautifulSoup

In [38]: soup = BeautifulSoup("""&lt;div&gt;
     ...: &lt;p class="tabbed" style="margin-top:2px;"&gt;&lt;span class="tab"&gt;&lt;strong&gt;LANGUAGES&lt;/strong&gt;&lt;/span&gt;Cantonese&lt;/p&gt;
     ...: &lt;p class="tabbed" style="margin-top:2px;"&gt;&lt;span class="tab"&gt;&lt;/span&gt;English&lt;/p&gt;
     ...: &lt;p class="tabbed" style="margin-top:2px;"&gt;&lt;span class="tab"&gt;&lt;/span&gt;Putonghua&lt;/p&gt;
     ...: &lt;p class="tabbed"&gt;&lt;span class="tab"&gt;&lt;strong&gt;GENDER&lt;/strong&gt;&lt;/span&gt;Male&lt;/p&gt;
     ...:    &lt;/div&gt;""", "html")

In [39]: soup.find(lambda tag: tag.text.startswith('GENDER')).text[6:]
Out[39]: u'Male'
</code></pre>

python html text tags beautifulsoup