前言
自己在做笔记的时候,经常看到网上一些别人的言论又华丽又呼哨,想直接粘贴复制又因为太长导致格式出现误差,这个时候就需要一个小工具来自动完成该功能。
工具
- python 3.6
- 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'youhua.html'
htmlfile = open(file_path, 'r', encoding='UTF-8')
htmlpage = htmlfile.read()
text = text_maker.handle(htmlpage)
open("1.md", "w").write(text)