【问题标题】:Read outlook mail in html format以html格式阅读outlook邮件
【发布时间】:2017-02-19 05:53:28
【问题描述】:

我在 Microsoft Outlook 中收到一封包含 html 表格的邮件。我想将其解析为熊猫数据框。

我已经编写了一个脚本,它使用漂亮的汤来将 html 文本解析到数据框中。但我首先在阅读 html 中的电子邮件时遇到了困难。

找到消息后,我正在使用以下代码将其读入文本文件。但它将文本写为 /n 分隔的字符串,而不是像我期望的那样的数据。这意味着我不能使用漂亮的汤将其放入数据框中。

我找到了很多关于如何编写和发送 html 邮件的示例,但没有找到如何阅读 html 格式的邮件。有什么想法吗?

contents = msg.Body.encode('ascii', 'ignore').decode('ascii')
contents_file = open("U:\body.txt", "w")
contents_file.write(contents)               
contents_file.close()

【问题讨论】:

    标签: python html email outlook


    【解决方案1】:

    自己找到了答案。我应该使用 msg.HTMLBody 而不是 msg.Body

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-05
      • 2018-07-08
      相关资源
      最近更新 更多