Python Library Reference
Previous: Up: 8.1 HTMLParser Next:


8.1.1 Example HTML Parser Application

As a basic example, below is a very basic HTML parser that uses the HTMLParser class to print out tags as they are encountered:

from HTMLParser import HTMLParser
class MyHTMLParser(HTMLParser):
 def handle_starttag(self, tag, attrs):
 print "Encountered the beginning of a %s tag" % tag
 def handle_endtag(self, tag):
 print "Encountered the end of a %s tag" % tag

Python Library Reference
Previous: Up: 8.1 HTMLParser Next:

Release 2.5.2, documentation updated on 21st February, 2008.
See About this document... for information on suggesting changes.

AltStyle によって変換されたページ (->オリジナル) /