muri 发表于 2015-12-2 08:05:14

[Python學習筆記] 抓出msg信件檔裡的附件檔案

  想要把msg信件檔案的附件抓出來做處理,找到了這個Python 模組 msg-extractor
  使用十分容易,但是這個模組是要在terminal裡執行,無法直接打在IDLE的編輯器上
  所以稍微做了修改,使用 subprocess 模組來打指令就可以了
  
  以下為程式碼 完整程式碼在我的 Github
  
  



#放置msg檔的檔案路徑
srcfilePath=os.path.join('C:\\', 'Python2.7.10')
#msg 檔名
fileName='123.msg'
def MsgToExcelDatabase(srcfilePath,fileName):
MailmsgPath=os.path.join(srcfilePath,fileName)
#使用 subprocess執行打command的動作
#start extract attachment from 123.msg
DIR = os.path.join('C:\\', 'Python2.7.10', 'msg-extractor-master', 'ExtractMsg.py')
subprocess.call(['python', DIR, MailmsgPath])
#把路徑與檔名放入寫好的 def
MsgToExcelDatabase(srcfilePath,fileName)
页: [1]
查看完整版本: [Python學習筆記] 抓出msg信件檔裡的附件檔案