confused by HTMLParser class

globalrev skanemupp at yahoo.se
Tue May 27 21:20:06 EDT 2008


tried all kinds of combos to get this to work.


http://docs.python.org/lib/module-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


from HTMLParser import HTMLParser
import urllib
import myhtmlparser

x = MyHTMLParser(HTMLParser())
site = urllib.urlopen("http://docs.python.org/lib/module-
HTMLParser.html")
for row in site:
    print x.handle_starttag()



More information about the Python-list mailing list