PyDocs

Nav

Structured Markup Processing Tools

HTMLParser

  • HTMLParser(*, convert_charrefs=True, scripting=False)
Find tags and other markup and call handler functions.

Usage:
    p = HTMLParser()
    p.feed(data)
    ...
    p.close()

Start tags are handled by calling self.handle_starttag() or
self.handle_startendtag(); end tags by self.handle_endtag().  The
data between tags is passed from the parser to the derived class
by calling self.handle_data() with the data as argument (the data
may be split up in arbitrary chunks).  If convert_charrefs is
True the character references are converted automatically to the
corresponding Unicode character (and self.handle_data() is no
longer split in chunks), otherwise they are passed by calling
self.handle_entityref() or self.handle_charref() with the string
containing respectively the named or numeric reference as the
argument.
Changed in 3.4, 3.5, 3.14.1
  • 3.4: convert_charrefs keyword argument added.
  • 3.5: The default value for argument convert_charrefs is now True.
  • 3.14.1: Added the scripting parameter.
Members of HTMLParser

c

close
Handle any buffered data.

f

feed
Feed data to the parser.

g

get_starttag_text
Return full source of start tag: '<...>'.
getpos
Return current line number and offset.

h

handle_charref
This method is called to process decimal and hexadecimal numeric character references of the form &#NNN; and &#xNNN;.
handle_comment
This method is called when a comment is encountered (e.g.
handle_data
This method is called to process arbitrary data (e.g.
handle_decl
This method is called to handle an HTML doctype declaration (e.g.
handle_endtag
This method is called to handle the end tag of an element (e.g.
handle_entityref
This method is called to process a named character reference of the form &name; (e.g.
handle_pi
Method called when a processing instruction is encountered.
handle_startendtag
Similar to handle_starttag(), but called when the parser encounters an XHTML-style empty tag (<img ...
handle_starttag
This method is called to handle the start tag of an element (e.g.

r

reset
Reset this instance.

u

unknown_decl
This method is called when an unrecognized declaration is read by the parser.
0 Examples
No examples for html.parser/HTMLParser.
See Also
No see-alsos for html.parser/HTMLParser
0 Notes
No notes for HTMLParser