我写了很多文章,用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])