I'm using the gmail API to parse through my gmail message body. It works other than when the body is in an html. Does anyone know how I can just extract the text within the email? If not, how I can just ignore emails with html?
Eventually I want to implement this for personal/professional emails in which there likely won't be html in it.
def message_converter(message_id): message = service.users().messages().get(userId='me', id=message_id,format='raw').execute() msg_str = str(base64.urlsafe_b64decode(message['raw'].encode('ASCII')),'UTF-8') mime_msg = email.message_from_string(msg_str) if mime_msg.is_multipart(): for payload in mime_msg.get_payload(): # if payload.is_multipart(): ... print (payload.get_payload()) else: print (mime_msg.get_payload())