So I'm using Mailosaur and I want to get the text of an HTML element in the E-Mail, in the Docs it says something like that:
# Wait for the message
message = client.messages.get("{SERVER_ID}", criteria)
# Extract the verification code from HTML
dom = BeautifulSoup(html, 'html.parser')
verification_code = dom.find('.verify-code').text
print(verification_code)
But I get the error:
dom = BeautifulSoup(html, 'html.parser')
NameError: name 'html' is not defined
I tried something like that too:
dom = BeautifulSoup(message.html, 'html.parser')
But I get the error:
TypeError: object of type 'MessageContent' has no len()
I hope someone can help me. Thanks.
Edit: So here is the rest of the Code:
from mailosaur.models import SearchCriteria
from mailosaur import MailosaurClient
from bs4 import BeautifulSoup
client = MailosaurClient('MyAPIKey')
criteria = SearchCriteria()
criteria.sent_to = "something.{ServerID}@mailosaur.io"
message = client.messages.get(ServerID, criteria)
if 'Email Verification' in message.subject: # Works
dom = BeautifulSoup(html, 'html.parser') # Doesn't work
verification_code = dom.find('') # Not Sure how to use this here, but that shouldn't be a big problem
print(verification_code)
Edit 2:
So I got it working but I'm not sure on how to use dom.find('').
The HTML Element looks like this:
<div style="font-family: arial,helvetica,sans-serif; mso-line-height-rule: exactly; color:#313131; text-align: center; font-size: 50px; letter-spacing: 20px; line-height: 120px;"> 619718 the Code at the end is the think I need