19.2. sgmllib — Simple SGML parser

Deprecated since version 2.6:

Deprecated since version 2.6: The sgmllib module has been removed in Python 3.0.

This module defines a class SGMLParser which serves as the basis for parsing text files formatted in SGML (Standard Generalized Mark-up Language). In fact, it does not provide a full SGML parser — it only parses SGML insofar as it is used by HTML, and the module only exists as a base for the htmllib module. Another HTML parser which supports XHTML and offers a somewhat different interface is available in the HTMLParser module.

class sgmllib.SGMLParser

The SGMLParser class is instantiated without arguments. The parser is hardcoded to recognize the following constructs:

  • Opening and closing tags of the form <tag attr="value" ...> and </tag>, respectively.
  • Numeric character references of the form &#name;.
  • Entity references of the form &name;.
  • SGML comments of the form <!--text-->. Note that spaces, tabs, and newlines are allowed between the trailing > and the immediately preceding --.

A single exception is defined as well:

exception sgmllib.SGMLParseError

Exception raised by the SGMLParser class when it encounters an error while parsing.

New in version 2.1:

New in version 2.1.