Developpez.com

Python

Choisissez la catégorie, puis la rubrique :

8.1.1 Example HTML Parser Application


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
See About this document... for information on suggesting changes.
Contacter le responsable de la rubrique Python

Partenaire : Hébergement Web