xoutil.html – Helpers for manipulating HTML

Deprecated since version 1.8.0.

This module defines utilities to manipulate HTML.

This module backports several utilities from Python 3.2.

Because now we deprecated it, we moved here documentation to remove it in one shot.

xoutil.html.entities – Definitions of HTML general entities

This module defines tree dictionaries, name2codepoint, codepoint2name, and entitydefs.

entitydefs is used to provide the entitydefs attribute of the xoutil.html.parser.HTMLParser class. The definition provided here contains all the entities defined by XHTML 1.0 that can be handled using simple textual substitution in the Latin-1 character set (ISO-8859-1).

xoutil.html.entitydefs

A dictionary mapping XHTML 1.0 entity definitions to their replacement text in ISO Latin-1.

xoutil.html.name2codepoint

A dictionary that maps HTML entity names to the Unicode codepoints.

xoutil.html.codepoint2name

A dictionary that maps Unicode codepoints to HTML entity names

xoutil.html.parser – A simple parser that can handle HTML and XHTML

This module defines a class HTMLParser which serves as the basis for parsing text files formatted in HTML (HyperText Mark-up Language) and XHTML.

Warning

This module has not being made Python 2.7 and 3.2 compatible.

class xoutil.html.HTMLParser(strict=True)

Create a parser instance. If strict is True (the default), invalid HTML results in HTMLParseError exceptions [1]. If strict is False, the parser uses heuristics to make a best guess at the intention of any invalid HTML it encounters, similar to the way most browsers do. Using strict=False is advised.

An :class`HTMLParser` instance is fed HTML data and calls handler methods when start tags, end tags, text, comments, and other markup elements are encountered. The user should subclass HTMLParser and override its methods to implement the desired behavior.

This parser does not check that end tags match start tags or call the end-tag handler for elements which are closed implicitly by closing an outer element.

Changed in version 3.2: strict keyword added

class xoutil.html.HTMLParseError

Exception raised by the HTMLParser class when it encounters an error while parsing and strict is True. This exception provides three attributes: msg is a brief message explaining the error, lineno is the number of the line on which the broken construct was detected, and offset is the number of characters into the line at which the construct starts.

xoutil.html.escape(s, quote=True)[source]

Replace special characters “&”, “<” and “>” to HTML-safe sequences

If the optional flag quote is true (the default), the quotation mark characters, both double quote (“) and single quote (‘) characters are also translated.

Todo

Remove this documentation.