基礎的な例として、HTMLParser クラスを使い、発見したタグを出力 する、非常に基礎的な HTML パーザを以下に示します。
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