How to remove html commands
<p>I have a .htm document. By using text_content(), I extracted the text from the document. 
Here is the text:</p>

<blockquote>
  <p>'PART II  \xa0\r\nThe Company\x92s common stock is traded on the over-the-counter market and is quoted on the NASDAQ Global Select Market under the symbol\r\nAAPL and on the Frankfurt Stock Exchange under the symbol APCD.  Price Range of Common Stock  The price range per share of common stock presented below represents the highest and lowest sales prices for the Company\x92s common stock\r\non the NASDAQ Global Select Market during each quarter of the two most recent years.  \xa0\r\nHolders  As of October\xa016, 2009, there were 30,573 shareholders of record.  Dividends\r\n The Company did not declare or pay cash dividends in either 2009 or 2008. The Company anticipates that for the foreseeable\r\nfuture it will retain any earnings for use in the operation of its business.  Purchases of Equity Securities by the Issuer and Affiliated\r\nPurchasers  None.  \xa0\r\n 33 '</p>
</blockquote>

<p>With this text, I need to remove a heading which is preceded and followed by a blank line. Thus, lines of the following form should be removed:</p>

<pre><code>\n
some text here\n
\n
</code></pre>

<p>I have a code that does that for .txt version of document. However, from .htm document, I realized that some weird things like \xa0\r\n are used to make words capital (for example). Is there any way to remove all of these things and correctly remove only the headings?</p>

<p>Here is the function that does remove the heading:</p>

<pre><code>def clean_text_passage(a_text_string):
    """REMOVE /n:  take a list of strings (some passage of text)
and remove noise which is defined as lines that are preceded
by a blank line and followed by a blank line that is lines of
this form will not be in the output
\n
some text here\n
\n
"""
    new_passage=[]
    p=[line+'\n' for line in a_text_string.split('\n')]
    passage = [w.lower().replace('&lt;/b&gt;\n', '\n') for w in p]

    if len(passage[0].strip())&gt;0:
       if len(passage[1].strip())&gt;0:
           new_passage.append(passage[0])

    for counter, text_line in enumerate(passage[:-1]):
        len_line_before=len(passage[counter-1].strip())
        len_line_after=len(passage[counter+1].strip())
        if len_line_before==len_line_after==0:
            continue
        if len(text_line.strip())!=0:
            new_passage.append(text_line)

    if len(passage[-2].strip())!=0:
        if len(passage[-1].strip())!=0:
            new_passage.append(passage[-1])

    return new_passage
</code></pre>

<p>I guess the key is to identify the heading in htm document.</p>

<p>Thank you so much for your time and help.</p>
