文档:
https://pypi.org/project/html2text/
安装:
|
|
|
|
|
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]
|
>>> 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='http://earth.google.com/'>world</a>!")
Hello, world!
>>> print(h.handle("<p>Hello, <a href='http://earth.google.com/'>world</a>!"))
Hello, world!
>>> # Don't Ignore links anymore, I like links
>>> h.ignore_links = False
>>> print(h.handle("<p>Hello, <a href='http://earth.google.com/'>world</a>!"))
Hello, [world](http://earth.google.com/)!