python解析mht文件_将不同内容类型的MHT文件提取到多个MHT-fi中

我正在编写一个mht脚本来解析一个mht文件,并从父对象中提取部分消息并将它们写入一个单独的mht文件

我写了下面的函数,在文件位置打开一个mht文件,搜索特定的内容,并将其写入一个新的mht文件def extract_content(self, file_location, content_id,extension):

first_part = file_location.split(extension)[0]

#checking if file exists

new_file = first_part + "-" + content_id.split('.')[0] + extension

while os.path.exists(new_file):

os.remove(new_file)

with open(file_location, 'rb') as mime_file, open(new_file, 'w') as output:

***#Extracting the message from the mht file***

message = message_from_file(mime_file)

t = mimetypes.guess_type(file_location)[0]

#Walking through the message

for i, part in enumerate(message.walk()):

#Check the content_id if the one we are looking for

if part['Content-ID'] == '':

***witing the contents***

output.write(part.as_string(unixfrom=False))

应用程序在pdf/octet>中的部分显然无法打开。在How do I write these Content-Type like application/pdf and

application/octet-stream in to mht files so that I am able to view the image or pdf in IE?

谢谢

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值