Skip to content

extractnetvshtml2text

MIT 3 9 70
330 (month) Dec 11 2020 2.0.7 (2 months ago)
1,349 7 94 GNU GPL 3
2020.1.16 (3 years ago) Dec 14 2008 1.0 million (month)

html2text is a Python library that allows developers to convert HTML code into plain text. It is designed to be easy to use, and it provides several options to customize the output.

The package uses the python's built-in html.parser to parse the HTML and then convert it to plain text.

html2text also comes with a CLI tool that can convert HTML files to text:

Usage: html2text [filename [encoding]]

Option  Description
--version   Show program's version number and exit
-h, --help  Show this help message and exit
--ignore-links  Don't include any formatting for links
--escape-all    Escape all special characters. Output is less readable, but avoids corner case formatting issues.
--reference-links   Use reference links instead of links to create markdown
--mark-code Mark preformatted and code blocks with [code]...[/code]

Example Use


from extractNet.extractNet import extractNet

#Initialize the model
en = extractNet()

#Extract structured data from text
text = "My phone number is 555-555-5555 and my email address is example@example.com"
data = en.extract(text)

#Print the extracted data
print(data)
{'phone_number': '555-555-5555', 'email': 'example@example.com'}
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/)!"

Alternatives / Similar