Would anyone show me how to use htmllib?

Alex Martelli aleaxit at yahoo.com
Sat Oct 28 06:37:13 EDT 2000


<jackxh at my-deja.com> wrote in message news:8te2ch$8ou$1 at nnrp1.deja.com...
> Hi
> I have read the python library reference. I am a python newbe, I think I
> have to overload some functions to get it working. Could anyone give to
> a example to show me how it works?

Override, rather than overload.  Normally, yes.  Unless
you just want the list of links from an HTML page, in
which case this simple script will do it:

import htmllib
import formatter

parser=htmllib.HTMLParser(formatter.NullFormatter())
parser.feed(open('myfile.html').read())
parser.close()

print parser.anchorlist


Now, if, instead of just instantiating HTMLParser, you
instantiate a class of your own that derives from it
and overrides the methods you're interested in, then
you can do different things.  But it's hard to give a
meaningful example without knowing what it is you
want to do.  For some tasks, building your own
formatter-class and using the plain parser-class from
htmllib may be a simpler way, too.


Alex






More information about the Python-list mailing list