安装pip install html2text
import html2text as ht
if __name__ == '__main__':
text_maker = ht.HTML2Text()
text_maker.ignore_links = True
text_maker.bypass_tables = False
file_path = r'C:/Users/bjliuchenhong/PycharmProjects/pythonProject/tools/htmlToMarkdown/file/ret.html'
htmlfile = open(file_path, 'r', encoding='UTF-8')
htmlpage = htmlfile.read()
text = text_maker.handle(htmlpage)
print(text)
open("C:/Users/bjliuchenhong/PycharmProjects/pythonProject/tools/htmlToMarkdown/file/1.md", "w", encoding='UTF-8').write(text)
下面这个不是很好用,应该是有字数限制。
import aspose.words as aw
doc = aw.Document("C:/Users/bjliuchenhong/PycharmProjects/pythonProject/tools/htmlToMarkdown/file/ret.html")
doc.save("C:/Users/bjliuchenhong/PycharmProjects/pythonProject/tools/htmlToMarkdown/file/Output.md")
没有评论