我正在尝试将来自Outlook的电子邮件正文转换为熊猫数据框。我该如何分解msg.Body
成可以写给acsv
并吸收到大熊猫中的行?
到目前为止,这是我所拥有的(我可以使用它来打印到屏幕上并复制并粘贴到Excel中以进行更多操作):
import win32com.client
import win32com
outlook = win32com.client.Dispatch('Outlook.Application').GetNameSpace('MAPI')
FedEx_Claims = outlook.GetDefaultFolder(6).Folders['FedExClaims']
for msg in FedEx_Claims.Items:
body = msg.Body
print(body)
我尝试将主体强制为字符串,但是初步测试并未表明它被视为字符串,因为我无法过滤为仅包含带有“:”的行。
s_msg = str(body)
for line in s_msg:
if ':' in line:
print(s_msg, end='')
任何帮助将不胜感激。
注意:我目前无法访问IMAP
,但是我问我的IT部门是否可以更改。
使用exchangelib
在https://pypi.org/project/exchangelib/
from exchangelib import DELEGATE, Account, Credentials, Configuration
creds = Credentials(
username='X', password='X'
)
config = Configuration(server='X.ca', credentials=creds)
account = Account(
primary_smtp_address="[email protected]",
autodiscover=False,
config=config,
access_type=DELEGATE
)
for item in account.inbox.all().order_by('-datetime_received')[:1]:
print(item.body)
item.body内容将为html格式,然后用于pandas.read_html
读取/结构化内容
https://pandas.pydata.org/pandas-docs/version/0.23.4/generated/pandas.read_html.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句