gpt4 book ai didi

python - 使用 Python 解析所有电子邮件正文 html

转载 作者:行者123 更新时间:2023-11-28 22:44:13 26 4
gpt4 key购买 nike

基本上,我想使用 Python 解析来 self 的 gmail 的所有电子邮件正文。 StackOverflow 上的解决方案很少,例如我找到的最接近的是 here他使用 Python 中的 poplib 来解析所有电子邮件。另一个是 this one他在其中使用 .get_payload() 获取电子邮件正文

但是,当我使用 poplib 解析电子邮件时(如上例所示),我会执行每封电子邮件 message.get_payload() 以获取电子邮件正文、字符串我得到的与来自电子邮件本身的 html 不同,即它在我解析的字符串中有 3D=\namp; 等字符串电子邮件正文。

我想知道是不是 POP 协议(protocol)的问题,所以我需要使用其他协议(protocol),比如 imaplib (但我不知道如何解析所有的电子邮件,比如 poplib)。或者,我可以修改给定 example获取正确的电子邮件正文。

最佳答案

message.get_payload(decode=True) 将是您最好的 friend :)

根据the docs :

Optional decode is a flag indicating whether the payload should be decoded or not, according to the Content-Transfer-Encoding header.

HTH

关于python - 使用 Python 解析所有电子邮件正文 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29788749/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com