Python: msg.get_payload() discards needed data, solution wanted
===

Hi I have gone through various posts here but none of them answer my question, I have two problems,
1.
I have written a script to get emails using poplib, everythig works fine until when I am trying to parse the body of the email it get rid of the <td> tags plus the data inside them, I  am now given up and am here for help hope you guys will guide me to the right direction as where I am doing wrong or what should I do to make it work.

Here's the source of parser script

    import sys
    import socket
    import poplib
    import email
    import csv
    import re
    try:
      host = "mail.someserver.com"
      mail = poplib.POP3(host)
      print mail.getwelcome()
      print mail.user("username@someserver.com")
      print mail.pass_("qaiaJWkvZT")
      print mail.stat()
      print mail.list()
      print ""
    
      emailWriter = csv.writer(open('emailMessages.csv', 'wb'), delimiter=',', quotechar='\'', quoting=csv.QUOTE_MINIMAL)
      emailWriter.writerow(['Messages'])
      if mail.stat()[1] > 0:
          print "You have new mail."
      else:
          print "No new mail."
    
      print ""
    
      numMessages = len(mail.list()[1])
      for i in range(numMessages):
          for j in mail.retr(i+1)[1]:
              #print j
              msg = email.message_from_string(j) # new statement
              print msg.get_payload(decode=True)
              #emailWriter.writerow([msg.get_payload(decode=True)]) # new statement
              
      mail.quit()
      input("Press any key to continue.")
    except socket.error as e:
      print "Something went wrong! :(\nREASON:\n{0}:{1}".format(e.errno, e.strerror)
      raise
    except:
      print "Something went wrong!", sys.exc_info()[0]
      raise

Here's the output the above script generates

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or
    g/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <style type="text/css">
    BODY {
    
    
    
    
    
    
    
    }
    TD {
    
    
    
    }
    TH {
    
    
    }
    H1 {
    
    }
    TABLE,IMG,A {
    
    }
    </style>
    </head>
    <body>
    
    
    <p><strong>PO Number:</strong> 35164</p>
    
    <p><strong>Ship To:</strong><br />
    Joe Pasloski<br />
    16 Redwood Drive<br />Yorkton, SK  S3N2X7<br />
    204-473-2218</p>
    
    
    <table cellspacing="0" cellpadding="5" border="1" width="710" align="left">
    <tr>
    
    
    
    </tr>
    <tr>
    
    
    
    </tr>
    </table>
    </body>
    </html>

However if I change the script to print j variable directly inside the loop, it gives me this

    Return-Path: <orders@someserver.com>
    Delivered-To: username@someserver.com
    Received: (qmail 7636 invoked by uid 48); 14 Jul 2012 23:29:11 -0000
    Date: 14 Jul 2012 23:29:11 -0000
    Message-ID: <20120714232911.7635.qmail@b.inetuhosted.net>
    To: username@someserver.com
    Subject: Drop Ship Order - Joe Pasloski
    From: Someserver.com <orders@someserver.com>
    X-Mailer: PHP/5.2.17
    MIME-Version: 1.0
    Content-Type: multipart/alternative;
             boundary="2631183869_50020"
    Reply-to: SomeServer.com <orders@someserver.com>
    X-Antivirus: avast! (VPS 120714-2, 07/15/2012), Inbound message
    X-Antivirus-Status: Clean
    
    --2631183869_50020
    Content-Type: text/plain;
            charset="iso-8859-1"
    Content-Transfer-Encoding: 8bit
    
    
    
    --2631183869_50020
    Content-Type: text/html;
            charset="iso-8859-1"
    Content-Transfer-Encoding: 8bit
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or
    g/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <style type="text/css">
    BODY {
            MARGIN-TOP: 10px;
            MARGIN-BOTTOM: 10px;
            MARGIN-LEFT: 10px;
            MARGIN-RIGHT: 10px;
            FONT-SIZE: 12px;
            FONT-FAMILY: arial,helvetica,sans-serif
            PADDING: 0px;
    }
    TD {
            FONT-SIZE: 12px;
            FONT-FAMILY: arial,helvetica,sans-serif
            COLOR: #000000;
    }
    TH {
            FONT-SIZE: 13px;
            FONT-FAMILY: arial,helvetica,sans-serif
    }
    H1 {
        FONT-SIZE: 20px
    }
    TABLE,IMG,A {
            BORDER: 0px;
    }
    </style>
    </head>
    <body>
    
    
    <p><strong>PO Number:</strong> 35164</p>
    
    <p><strong>Ship To:</strong><br />
    Joe Pasloski<br />
    16 Redwood Drive<br />Yorkton, SK  S3N2X7<br />
    204-473-2218</p>
    
    <p><strong>Items:</strong>
    <table cellspacing="0" cellpadding="5" border="1" width="710" align="left">
    <tr>
            <th align="left" width="100">SKU</th>
            <th align="left" width="550">Product</th>
            <th align="left" width="60">Qty</th>
    </tr>
    <tr>
            <td>JJ-Hamper-Firetruck</td>
            <td>Frankie's Fire Truck Laundry Hamper</td>
            <td>1</td>
    </tr>
    </table>
    </body>
    </html>

If i need to process the raw message how can i effectively get the body part of the message stripping out the unnecessary html tags without losing any data? Or if it is possible through using get_payload() method, what can i do to make it work.

Please help!

2.
Further more is there a way I can get all the SKU information contained in the table using regex? if you can provide me that too that will be a plus. Thanks a ton