Python 如何在.msg文件体中获取表
我想用Python获得一个位于一个.msg文件主体内的表。我可以获取主体内容,但我需要将表拆分为数据帧 我可以得到正文内容,但我不能分离正文的表格Python 如何在.msg文件体中获取表,python,outlook,msg,Python,Outlook,Msg,我想用Python获得一个位于一个.msg文件主体内的表。我可以获取主体内容,但我需要将表拆分为数据帧 我可以得到正文内容,但我不能分离正文的表格 import win32com.client import os dir = r"C:\Users\Murilo\Desktop\Emails\030" file_list = os.listdir(dir) for file in file_list: if file.endswith(".msg"): outlook
import win32com.client
import os
dir = r"C:\Users\Murilo\Desktop\Emails\030"
file_list = os.listdir(dir)
for file in file_list:
if file.endswith(".msg"):
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
msg = outlook.OpenSharedItem(dir + "/" + file)
print(msg.Body)
我需要存在于body content中的表,但不是所有body,我将查看extract\u msg库。它应该允许您以普通XML格式打开.msg文件,并且非常容易从内容中提取表
msg = extract_msg.Message(fileLoc)
msg_message = msg.body
content = ('Body: {}'.format(msg_message))
如果是HTML表格,请使用
MailItem.HTMLBody
(而不是纯文本Body
)并从HTML中提取表格。Outlook对象模型提供了三种处理项目体的主要方法:
但我认为最简单、最干净的方法是使用单词对象模型。您可以在文章中阅读更多有关如何处理Word对象模型以及如何使用它提取表格内容的内容。谢谢!我使用了它,并与熊猫完美配合(阅读html)。这将创建包含电子邮件正文上所有表的数据帧列表。列表的每一项都是主体上一个表的一个数据帧。data=pd.read\u html(msg.HTMLBody)