来自电子邮件 html 内容的美丽汤解析崩溃

问题描述

我正在尝试使用 Beautiful Soup 解析包含 html 内容的电子邮件。问题是当我想捕获例如电子邮件中包含的表格时。

由于编码问题,我无法正确解析并按表、tr、td...找到元素...

电子邮件内容:

  • 表声明

      <tab=\r\nle\r\nborder=3D\'0\' cellspacing=3D\'0\' cellpadding=3D\'5\' style=3D\'font-family: Aria=\r\nl;\r\nfont-size:13px;\'>
        <td>
        </td>
        <td>
    
  • 列声明

    购买

理论上,邮件编码是 UTF-8:

Content-Type: text/html; charset=UTF-8

python中的编码是这样的:

    for sent in msgs[0]:
    if type(sent) is tuple:
        # encoding set as utf-8
        content = str(sent[1],'utf-8')
        data = str(content)

sent[1]是邮件内容,然后我用UTF-8将数据编码成str,以便在Beautiful Soup中使用。

问题是,如何修复邮件内容编码?我试图替换,蚂蚁其他人,但没有奏效。

提前致谢。

编辑如果我重新发送电子邮件,它会起作用

解决方案:

content = quopri.decodestring(sent[1]).decode('latin-1')

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...