HTMLLib.py use

Tamito Kajiyama kajiyama at grad.sccs.chukyo-u.ac.jp
Fri May 7 10:44:48 EDT 1999


Matthew Cepl <cepl at fpm.cz> writes:
| 
| OK, not it's much better, there is no error message. But still, there
| is no output from the script. I would like to get just description in
| metatag DESCRIPTION of given HTML page.

Your script works fine for me (with Python 1.5.2 on a Linux box).  What
version of Python on what platform are you using?

Also, attributes of the META element can appear in arbitrary order, but
the do_meta() method of the WPage class expects that the 'name' and
'content' attributes appear in this order.  One possible improvement:

    def __init__(self, verbose=0):
        self.description = None
        ...
    def do_meta(self, attributes):
        name = content = None
        for a, v in attributes:
            exec('%s = "%s"' % (a, v))
        if name == 'description':
            self.description = content

| BTW, when I shall need a content of TITLE element it should be done
| via start_title() or how?

Reasonable implementations of start_title() and end_title() have been
built in the standard HTMLParser class.  See the source code.

--
KAJIYAMA, Tamito <kajiyama at grad.sccs.chukyo-u.ac.jp>




More information about the Python-list mailing list