Scraping newbie here. I'm trying to write a scraper with BeautifulSoup that scrapes html tables from emails in a Gmail account. Using IMAP, the script checks an inbox intermittently. I'm not sure though how to extract the HTML from the email, which is needed for scraping the tables. Currently, it extracts the body text, not the raw HTML:
m.select("[Gmail]/All Mail")
resp, items = m.search(None, "ALL")
items = items[0].split()
for emailid in items:
resp, data = m.fetch(emailid, "(RFC822)")
email_body = data[0][1] # getting the mail content
mail = email.message_from_string(email_body)
soup = BeautifulSoup(mail)
tables = soup.find_all("table", width=900)
...