def _parse_email(email_body): """ Parse the email body from Imovirtual :param email_body: email body text :return: parsed data """ product_reference = '' contact_name = '' contact_email = '' contact_phone = '' comment = '' soup = BeautifulSoup(email_body, 'html.parser') td = soup.td(text=re.compile('Refer\xeancia:')) if td: product_reference = td[0].parent.next_sibling.text td = soup.td(text=re.compile('Nome:')) if td: contact_name = td[0].parent.next_sibling.text td = soup.td(text=re.compile('E-mail:')) if td: contact_email = td[0].parent.next_sibling.text td = soup.td(text=re.compile('Telefone:')) if td: contact_phone = td[0].parent.next_sibling.text td = soup.td(text=re.compile('Coment\xe1rio:')) if td: comment = td[0].next_sibling.text result = { 'product_code': product_reference, 'contact_name': contact_name, 'contact_email': contact_email, 'contact_phone': contact_phone, 'name': comment } _logger.info('Extracted data from email: %s', result) return result