Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

Make every effort to properly decode HTML, because HTML is unicode, dammit!

Project description

Latest Version Build & Tests Status Test Coverage License: MIT

Make every effort to properly decode HTML, because HTML is unicode, dammit!

Features

  • Very easy to use with integrations for requests and urlopen().
  • Utilizes information from HTTP headers, inline encoding declarations, and UTF BOM-s (Byte Order Marks), as well as falling back to making a best guess based on the raw data.
  • Improves upon BeautifulSoup’s great UnicodeDammit utility.

Installation

pip install htmldammit

Additionally, it is highly recommended to install the cchardet and/or the chardet libraries. This will enable the fallback to guessing the encoding based on the raw data.

pip install cchardet chardet

Basic usage

To decode any binary HTML content into unicode (passing HTTP headers is optional):

from htmldammit import decode_html
html = decode_html(raw_html, http_headers)

To get unicode HTML from a requests response:

from htmldammit.integrations.requests import get_response_html
response = requests.get('http://www.example.org/')
html = get_response_html(response)

To get unicode HTML from a urlopen() response:

from htmldammit.integrations.urllib import get_response_html
response = urlopen('http://www.example.org/')
html = get_response_html(response)

Project details


Release history Release notifications

This version
History Node

0.1.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
htmldammit-0.1.1-py2.py3-none-any.whl (8.2 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Jan 7, 2018
htmldammit-0.1.1.tar.gz (5.9 kB) Copy SHA256 hash SHA256 Source None Jan 7, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page