(original) (raw)
Index: HTMLParser.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/HTMLParser.py,v retrieving revision 1.11 diff -c -r1.11 HTMLParser.py *** HTMLParser.py 14 May 2002 15:50:11 -0000 1.11 --- HTMLParser.py 6 Jan 2003 04:42:02 -0000 *************** *** 73,78 **** --- 73,82 ---- ... p.close() + Facilitates HTML parsing by providing a callback mechanism + similar to SAX parsing. To receive callbacks from the parser, + subclass HTMLParser and implement the handle_* methods. + 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 *************** *** 332,370 **** --- 336,393 ---- # Overridable -- finish processing of start+end tag: def handle_startendtag(self, tag, attrs): + """called when a start+end tag is encountered: + in this example, the value of tag is 'tag' and attrs is a list + of tuples: [('foo', 'bar')]""" self.handle_starttag(tag, attrs) self.handle_endtag(tag) # Overridable -- handle start tag def handle_starttag(self, tag, attrs): + """called when a start tag is encountered: + in this example, the value of tag is 'tag' and attrs is a list of + tuples: [('foo', 'bar')]""" pass # Overridable -- handle end tag def handle_endtag(self, tag): + """called when an end tag is encountered: """ pass # Overridable -- handle character reference def handle_charref(self, name): + """called when a character reference is encountered: { + in this example, the value of name is '123'""" pass # Overridable -- handle entity reference def handle_entityref(self, name): + """called when an entity reference is encountered: &bar;+ in this example, the value of name is 'bar'""" pass # Overridable -- handle data def handle_data(self, data): + """called when data is encountered: foo bar+ in this example, the value of data is 'foo bar'""" pass # Overridable -- handle comment def handle_comment(self, data): + """called when a comment is encountered: + in this example, the value of data is 'foo bar'""" pass # Overridable -- handle declaration def handle_decl(self, decl): + """called when a declaration is encountered: + in this example, the value of decl is 'DOCTYPE foo'""" pass # Overridable -- handle processing instruction def handle_pi(self, data): + """called when a processing instruction is encountered: