轻松记录您
灵感和创意

Python将DOCX转换为markdown文件

我写了很多文章,用docx来保存,现在想把他放到博客上,我该怎么做?复制粘贴?不!我要格式转换!

DOCX转换成HTML

from pydocx import PyDocXhtml = PyDocX.to_html(r”E:\工作管理\环境搭建\文档上传\格式转换\test.docx”)f = open(“test.html”, ‘w’, encoding=”utf-8″)f.write(html)f.close()

HTML转换成Markdown

from pydocx import PyDocXimport html2text as hthtml = PyDocX.to_html(r”E:\工作管理\环境搭建\文档上传\格式转换\test.docx”)f = open(“test.html”, ‘w’, encoding=”utf-8″)f.write(html)f.close()text_maker = ht.HTML2Text()text_maker.bypass_tables = Falsepath =r”E:\工作管理\环境搭建\文档上传\格式转换\test.html”htmlfile = open(path,’r’,encoding=’UTF-8′)htmlpage = htmlfile.read()text = text_maker.handle(htmlpage)md = text.split(‘#’) open(“test.md”,”w”).write(md[1])

未经允许不得转载:坚果之云 Markdown » Python将DOCX转换为markdown文件
分享到: 更多 (0)

坚果云Markdown轻松记录您 灵感和创意

坚果云Markdown下载坚果云Markdown介绍