将HTML转换为等效的Markdown结构化文本。
项目描述
html2text
html2text 是一个 Python 脚本,它可以将 HTML 页面转换为干净的、易于阅读的纯 ASCII 文本。更好的是,这个 ASCII 文本也恰好是有效的 Markdown(一种文本到HTML的格式)。
用法: html2text [filename [encoding]]
选项 | 描述 |
---|---|
--version |
显示程序版本号并退出 |
-h , --help |
显示此帮助信息并退出 |
--ignore-links |
不要包含任何链接的格式化 |
--escape-all |
转义所有特殊字符。输出更难阅读,但避免了角落案例格式化问题。 |
--reference-links |
使用参考链接而不是链接来创建 Markdown |
--mark-code |
使用 [code]...[/code] 标记预格式化和代码块 |
有关完整选项列表,请参阅 文档
或者您可以在 Python
中使用它
>>> import html2text
>>>
>>> print(html2text.html2text("<p><strong>Zed's</strong> dead baby, <em>Zed's</em> dead.</p>"))
**Zed's** dead baby, _Zed's_ dead.
或者使用一些配置选项
>>> import html2text
>>>
>>> h = html2text.HTML2Text()
>>> # Ignore converting links from HTML
>>> h.ignore_links = True
>>> print h.handle("<p>Hello, <a href='https://www.google.com/earth/'>world</a>!")
Hello, world!
>>> print(h.handle("<p>Hello, <a href='https://www.google.com/earth/'>world</a>!"))
Hello, world!
>>> # Don't Ignore links anymore, I like links
>>> h.ignore_links = False
>>> print(h.handle("<p>Hello, <a href='https://www.google.com/earth/'>world</a>!"))
Hello, [world](https://www.google.com/earth/)!
最初由Aaron Swartz编写。此代码在GPLv3下分发。
如何安装
html2text
可在PyPI上找到 https://pypi.ac.cn/project/html2text/
$ pip install html2text
如何运行单元测试
tox
查看覆盖率结果
coverage html
然后在浏览器中打开 ./htmlcov/index.html
文件。
文档
文档位于 此处
项目详情
关闭
html2text-2024.2.26.tar.gz的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | 05f8e367d15aaabc96415376776cdd11afd5127a77fce6e36afc60c563ca2c32 |
|
MD5 | b67974402e2e3ea0e7d611ce3096388c |
|
BLAKE2b-256 | 1a43e1d53588561e533212117750ee79ad0ba02a41f52a08c1df3396bd466c05 |