python 十行代码系列(二):html转换为markdown

前言

自己在做笔记的时候,经常看到网上一些别人的言论又华丽又呼哨,想直接粘贴复制又因为太长导致格式出现误差,这个时候就需要一个小工具来自动完成该功能。

工具

代码

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)

说明

代码地址及使用说明

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容