Previous: 13.1 HTMLParser Up: 13.1 HTMLParser Next: 13.2 sgmllib


13.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


Previous: 13.1 HTMLParser Up: 13.1 HTMLParser Next: 13.2 sgmllib
Release 2.2.3, documentation updated on 30 May 2003.
See About this document... for information on suggesting changes.

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