将HTML转换为等效的降价结构化文本。

html2text的Python项目详细描述


html2文本

Build StatusCoverage StatusDownloadsVersionWheel?FormatLicense

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("<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/)!

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

如何安装

html2text在pypi上可用 https://pypi.org/project/html2text/

$ pip install html2text

如何运行单元测试

tox

查看覆盖率结果:

coverage html

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

文档

文档寿命here

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
在reducer中迭代自定义可写组件时出现java问题   属性文件中属性的java命名约定   任务链关闭的java Executor服务   java从Eclipse中的字段生成多个构造函数   java通过继承读取Json   java在不知道密钥的情况下解析json   java camel cxf如何在电子邮件中发送soap请求响应   java程序似乎跳过了if语句的一部分,在移回正确位置之前先移到else语句   测试简单的Java加密/解密inputFileName不存在   java从Jenkins REST API获取所有作业的所有构建的构建细节   java基本包装器和静态“类型”类对象   在WebSphere8.5上部署java代码   java对象相等(对象引用“=”)   java MongoDB整型字段到枚举的转换   每次我重新导入gradle时,IntelliJ都会不断重置Java设置   类型使用键或索引从Java中的数据类型检索值   在Java的列表接口中需要listIterator()和iterator()是什么?