如何安装html2text,Python html2text包_程序模块 - PyPI - Python中文网

html2text是一个Python脚本,用于将HTML转换为清晰易读的ASCII纯文本。它支持链接格式化和Markdown输出,并提供多种配置选项。该项目最初由亚伦·斯沃茨创建,遵循GPLv3许可。要安装,可以使用`pip install html2text`。通过调用`html2text.html2text()`方法,可以将HTML字符串转换为文本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

html2文本

10ede945c915a07c5505f5e8969e1bd2.png7f480ad29eef37661dc5adf42787e46f.png687474703a2f2f62616467652e6b6c6f756435312e636f6d2f707970692f642f68746d6c32746578742e706e67687474703a2f2f62616467652e6b6c6f756435312e636f6d2f707970692f762f68746d6c32746578742e706e67687474703a2f2f62616467652e6b6c6f756435312e636f6d2f707970692f776865656c2f68746d6c32746578742e706e67687474703a2f2f62616467652e6b6c6f756435312e636f6d2f707970692f666f726d61742f68746d6c32746578742e706e67687474703a2f2f62616467652e6b6c6f756435312e636f6d2f707970692f6c6963656e73652f68746d6c32746578742e706e67

html2text是一个python脚本,它将一页html转换成干净、易于阅读的纯ascii文本。更好的是,ascii也是有效的标记(文本到html格式)。

用法:html2text [filename [encoding]]OptionDescription^{}Show program's version number and exit

^{}, ^{}Show this help message and exit

^{}Don't include any formatting for links

^{}Escape all special characters. Output is less readable, but avoids corner case formatting issues.

^{}Use reference links instead of links to create markdown

^{}Mark preformatted and code blocks with [code]...[/code]

有关选项的完整列表,请参见docs

或者您可以在Python:中使用它。

>>> import html2text

>>>

>>> print(html2text.html2text("

Zed's dead baby, Zed's dead.

"))

**Zed's** dead baby, _Zed's_ dead.

或者使用一些配置选项:>>> import html2text

>>>

>>> h = html2text.HTML2Text()

>>> # Ignore converting links from HTML

>>> h.ignore_links = True

>>> print h.handle("

Hello, world!")

Hello, world!

>>> print(h.handle("

Hello, world!"))

Hello, world!

>>> # Don't Ignore links anymore, I like links

>>> h.ignore_links = False

>>> print(h.handle("

Hello, world!"))

Hello, [world](https://www.google.com/earth/)!

最初由亚伦·斯沃茨撰写。此代码在gplv3下分发。

如何安装$ pip install html2text

如何运行单元测试tox

查看覆盖率结果:coverage html

然后在浏览器中打开./htmlcov/index.html文件。

文档

文档寿命here

欢迎加入QQ群-->: 979659372

9ddc589a9bae9dd81334056da3504a2c.png

推荐PyPI第三方库

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值