rest25/library/htmlparser.rst => rest262/library/htmlparser.rst
f1
2:mod:`HTMLParser` --- Simple HTML and XHTML parser
3==================================================
4
5.. module:: HTMLParser
6   :synopsis: A simple parser that can handle HTML and XHTML.
n7+ 
8+.. note::
9+ 
10+   The :mod:`HTMLParser` module has been renamed to :mod:`html.parser` in Python
11+   3.0.  The :term:`2to3` tool will automatically adapt imports when converting
12+   your sources to 3.0.
7
8
9.. versionadded:: 2.2
10
11.. index::
12   single: HTML
13   single: XHTML
14
17Unlike the parser in :mod:`htmllib`, this parser is not based on the SGML parser
18in :mod:`sgmllib`.
19
20
21.. class:: HTMLParser()
22
23   The :class:`HTMLParser` class is instantiated without arguments.
24
n25-   An HTMLParser instance is fed HTML data and calls handler functions when tags
n31+   An :class:`HTMLParser` instance is fed HTML data and calls handler functions when tags
26   begin and end.  The :class:`HTMLParser` class is meant to be overridden by the
27   user to provide a desired behavior.
28
29   Unlike the parser in :mod:`htmllib`, this parser does not check that end tags
30   match start tags or call the end-tag handler for elements which are closed
31   implicitly by closing an outer element.
32
33An exception is defined as well:
78   attributes can be preserved, etc.).
79
80
81.. method:: HTMLParser.handle_starttag(tag, attrs)
82
83   This method is called to handle the start of a tag.  It is intended to be
84   overridden by a derived class; the base class implementation does nothing.
85
n86-   The *tag* argument is the name of the tag converted to lower case.  The *attrs*
n92+   The *tag* argument is the name of the tag converted to lower case. The *attrs*
87   argument is a list of ``(name, value)`` pairs containing the attributes found
t88-   inside the tag's ``<>`` brackets.  The *name* will be translated to lower case
t94+   inside the tag's ``<>`` brackets.  The *name* will be translated to lower case,
89-   and double quotes and backslashes in the *value* have been interpreted.  For
95+   and quotes in the *value* have been removed, and character and entity references
90-   instance, for the tag ``<A HREF="http://www.cwi.nl/">``, this method would be
96+   have been replaced.  For instance, for the tag ``<A
97+   HREF="http://www.cwi.nl/">``, this method would be called as
91-   called as ``handle_starttag('a', [('href', 'http://www.cwi.nl/')])``.
98+   ``handle_starttag('a', [('href', 'http://www.cwi.nl/')])``.
99+ 
100+   .. versionchanged:: 2.6
101+      All entity references from :mod:`htmlentitydefs` are now replaced in the attribute
102+      values.
92
93
94.. method:: HTMLParser.handle_startendtag(tag, attrs)
95
96   Similar to :meth:`handle_starttag`, but called when the parser encounters an
97   XHTML-style empty tag (``<a .../>``).  This method may be overridden by
98   subclasses which require this particular lexical information; the default
99   implementation simple calls :meth:`handle_starttag` and :meth:`handle_endtag`.
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op