这里是一个Python新手。我目前正在尝试弄清楚如何解析我存储在特定文件夹中的所有 msg 文件,然后将正文保存到 csv 文件中。
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
msg = outlook.OpenSharedItem(r"C:\Users\XY\Documents\Email Reader\test.msg")
print(msg.Body)
del outlook, msg
到目前为止,我只找到了一种打开一个特定 msg 文件的方法,而不是我存储在文件夹中的所有文件。我认为我应该能够处理将数据存储在 csv 文件中,但我只是不知道如何读取多个 msg 文件。希望你能帮助我!
干杯
最佳答案
您可以尝试这样的方法来迭代目录中带有“.msg”扩展名的每个文件:
import os
pathname = os.fsencode('Pathname as string')
for file in os.listdir(pathname):
filename = os.fsdecode(file)
if filename.endswith(".msg"):
#Do something
continue
else:
continue
希望这有帮助!
关于python - 解析多个 "msg"文件并将正文存储在csv文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52608069/