Home > database >  How to copy and save the mhtml content?
How to copy and save the mhtml content?

Time:09-25

I use the python script to read and save the mhtml content which is saved by Chrome.

with open(file_path, 'r ') as mht:
    text = mht.read() 
    with open('/Users/mac/Downloads/new.mht', 'w') as mht2:
        mht2.write(text)

The content of the files are identical. But when I tried to open the new document with Chrome, the page is blank and there is an error "Malformed multipart archive: ..." in console.

Why is this happening? Thank you very much for any help!

CodePudding user response:

After I had compared the hex code of the two files, I found python script change line breaks from 0A0D which is '\r\n' to 0D '\n'. Force python keeps the line breaks:

with open('/Users/mac/Downloads/new.mht', 'w', newline='\r\n') as mht2:
    mht2.write(text)

will do.

  • Related