How to parse text from html file
<pre><code>import urllib2
import nltk
from HTMLParser import HTMLParser
from bs4 import BeautifulSoup




l = """&lt;TR&gt;&lt;TD&gt;&lt;small style=font-family:courier&gt; &gt;M. tuberculosis H37Rv|Rv3676|crp&lt;br /&gt;VDEILARAGIFQGVEPSAIAALTKQLQPVDFPRGHTVFAEGEPGDRLYIIISGKVKIGRR&lt;br /&gt;APDGRENLLTIMGPSDMFGELSIFDPGPRTSSATTITEVRAVSMDRDALRSWIADRPEIS&lt;br /&gt;EQLLRVLARRLRRTNNNLADLIFTDVPGRVAKQLLQLAQRFGTQEGGALRVTHDLTQEEI&lt;br /&gt;AQLVGASRETVNKALADFAHRGWIRLEGKSVLISDSERLARRAR&lt;br /&gt;&lt;/small&gt;&lt;TR&gt;&lt;td&gt;&lt;b&gt;&lt;big&gt;Blastp: &lt;a href="http://tuberculist.epfl.ch/blast_output/Rv3676.fasta.out"&gt; Pre-computed results&lt;/a&gt;&lt;/big&gt;&lt;/b&gt;&lt;TR&gt;&lt;td&gt;&lt;b&gt;&lt;big&gt;TransMembrane prediction using Hidden Markov Models: &lt;a href="http://tuberculist.epfl.ch/tmhmm/Rv3676.html"&gt; TMHMM&lt;/a&gt;&lt;/big&gt;&lt;/b&gt;&lt;base target="_blank"/&gt;&lt;TR&gt;&lt;td&gt;&lt;b&gt;&lt;big&gt;Genomic sequence&lt;/big&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;form action="dnaseq.php" method="get"&gt;"""

print l
</code></pre>

<p>I have one HTML line and want to extract the text which is embedded into the HTML tags. I have tried with all the available methods, but they are not working in my case. </p>

<p>How can I do it?</p>

<p>Expected output should be:</p>

<p>H37Rv|Rv3676|crp
VDEILARAGIFQGVEPSAIAALTKQLQPVDFPRGHTVFAEGEPGDRLYIIISGKVKIGRRAPDGRENLLTIMGPSDMFGELSIFDPGPRTSSATTITEVRAVSMDRDALRSWIADRPEISEQLLRVLARRLRRTNNNLADLIFTDVPGRVAKQLLQLAQRFGTQEGGALRVTHDLTQEEIAQLVGASRETVNKALADFAHRGWIRLEGKSVLISDSERLARRAR</p>

<p>I notice you import BeautifulSoup, so you can use BeautifulSoup to help you extract these information.</p>

<pre><code>soup = BeautifulSoup(l,"html.parser")
print soup.get_text()
</code></pre>

<p>I've tried and it worked, but the sentence in the last tag will also be extracted, you have to cut the result if needed.</p>

python