文件整理利器,HTML快速转换为简洁的MD文件

HTML和Markdown是两种非常重要的格式。HTML是用于创建网页的格式,而Markdown则是一种简单易读的文本格式,用于将文本转换为HTML。

如果正在寻找一种方法来将HTML文件转换为Markdown文件,那么可以使用Python来轻松完成这项任务。

# coding:utf-8
__author__ = 'Mr.数据杨'
__explain__ = '1.html文件转换MD文件'

import html2text as ht


def html_2_text(input_file, output_file):
    text_maker = ht.HTML2Text()
    # 读取html格式文件
    with open(input_file, 'r', encoding='UTF-8') as f:
        htmlpage = f.read()
    # 处理html格式文件中的内容
    text = text_maker.handle(htmlpage)
    # 写入处理后的内容
    with open(output_file, 'w', encoding='UTF-8') as f:
        f.write(text)


if __name__ == "__main__":
    input_file = "test.html"
    output_file = "result.md"

    html_2_text(input_file, output_file)

猜你喜欢

转载自blog.csdn.net/qq_20288327/article/details/122696952
今日推荐