Extract plain text from HTML
Project description
Extract plain text from HTML
How is plainhtml
different from .xpath("//text()")
from lxml
or .get_text()
from bs4
?
- Text extracted with
plainhtml
does not contain inline styles, JavaScript, comments and other text that is not normally visible to users plainhtml
normalizes whitespace, but in a way smarter than.xpath("normalize-space()")
, adding spaces around inline elements (which are often used as block elements in HTML), and trying to avoid adding extra spaces for punctuationplainhtml
can add newlines (e.g. after headers or paragraphs), so that the output text looks more like how it is rendered in browsers
Installation
$ pip install plainhtml
Example
>>> import plainhtml
>>> html = "<html><body><p>foo</p><p>bar</p></body></html>"
>>> plainhtml.extract_text(html)
'foo\n\nbar'
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for plainhtml-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3788765be6e8f5c6f47c4ea20db8e5583975f9a3b757ff0fc3a151aaa8ea8607 |
|
MD5 | 3290f0cffb6e6aac60db8c3864177e07 |
|
BLAKE2b-256 | c7f24873cb7dc7f8a595112fab937d8f6e753edb37875ea5fcfe421205954e75 |