如何使用python将.docx文件转换为html?

Fas*_*med 4 python-2.7

import mammoth

f = open("D:\filename.docx", 'rb')
document = mammoth.convert_to_html(f)
Run Code Online (Sandbox Code Playgroud)

我在运行此代码时无法获取 .html 文件,请帮助我获取它,当我转换为 .html 文件时,我没有将图像插入到 .html 文件中,请您帮我如何将图像从 .docx 转换为 .html?

SP *_* SP 6

尝试这个:

import mammoth

f = open("path_to_file.docx", 'rb')
b = open('filename.html', 'wb')
document = mammoth.convert_to_html(f)
b.write(document.value.encode('utf8'))
f.close()
b.close()
Run Code Online (Sandbox Code Playgroud)


小智 2

我建议你尝试下面的代码

    import mammoth
    with open("document.docx", "rb") as docx_file:
    result = mammoth.convert_to_html(docx_file)
    html = result.value
Run Code Online (Sandbox Code Playgroud)

  • 但我无法将图像从 .docx 文件转换为 .html 文件,你能帮我怎么做吗? (2认同)