是否可以在不附加页眉和页脚的情况下使用 Python 获取电子邮件正文?我目前的代码是
import imaplib
username = "username"
password = "password"
imap_server = imaplib.IMAP4_SSL("imap.gmail.com",993)
imap_server.login(username, password)
imap_server.select('INBOX')
def get_emails(email_ids):
"""
Takes in an array of email id's as input eg: ['1','7']
Returns an array of html strings corresponding to the given email id's"""
data = []
for e_id in email_ids:
status, response = imap_server.fetch(e_id, '(UID BODY[TEXT])')
data.append(response[0][1])
return data
一个输出的 HTML 字符串是这样的:
--0016e6d9770b63df7104cebab205 Content-Type: text/plain; charset=ISO-8859-1
This is some html code
--0016e6d9770b63df7104cebab205 Content-Type: text/html; charset=ISO-8859-1 <html>
<body>
<p>This is some html code</p>
</body>
</html>
--0016e6d9770b63df7104cebab205--
是否可以只使用没有标题的 HTML?例:我想看看
<html>
<body>
<p>This is some html code</p>
</body>
</html>
作为输出。谢谢!