这里有一些初学者问题,我已经使用imaplib连接到一个imap服务器并获取了一封电子邮件,它返回以下内容:
[('1 (BODY[HEADER.FIELDS (SUBJECT)] {62}', "Subject: Gmail is different. Here's what you need to know.\r\n\r\n"), ')']
我的问题是我如何只选择主题元素(“主题:Gmail是......”)。
我尝试过几种组合但尚未成功。
感谢您的帮助!
答案 0 :(得分:4)
a[0][1]
其中a是字符串。
答案 1 :(得分:0)
email=[('1 (BODY[HEADER.FIELDS (SUBJECT)] {62}', "Subject: Gmail is different. Here's what you need to know.\r\n\r\n"), ')']
for subj in (subject for element in email for subject in element if subject.startswith("Subject")):
print subj
""" Output
Subject: Gmail is different. Here's what you need to know.
"""