HTMLLib.py use

Matthew Cepl cepl at fpm.cz
Mon May 3 10:27:35 EDT 1999


Hi,

trying to learn using HTMLLib.py I did try the following code, but it gives
me error . Everything is included in this mail. What's wrong with me?

Thanks

================= Code =====================

from htmllib import HTMLParser
from string import lower
from htmlentitydefs import entitydefs
import sys

class WPage(HTMLParser):

    def __init__(self, verbose=0):
        self.testdata = ""
        HTMLParser.__init__(self, verbose)

    def do_meta(self, attributes):
        data = self.testdata
        if data and lower(attributes[0][1])=="description":
	            print 'Description:', str(attributes[1][1])

    def close(self):
        HTMLParser.close(self)


def test(args = None):

    try:
       f = open('test.html', 'r')
    except IOError, msg:
       print file, ":", msg
       sys.exit(1)
    data = f.read()
    x = WPage()
    x.feed(data)
    x.close()

if __name__ == '__main__':
    test()

============= Processed HTML file ============= <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN"> <html>  <head>  <title>  Some Title  </title>	<meta
name="description" content=  "A minimal introduction to programming by use of
the Python programming language.">  </head>  <body>  <p>  Hello, world!  </p>
 </body> </html> ============= Output of PYTHON ============= C:\Program
Files\Python\Contrib\SiteMap>python WPage.py Traceback (innermost last): 
File "WPage.py", line 34, in ?	test()	File "WPage.py", line 30, in test 
x.feed(data)  File "C:\Program Files\python\lib\sgmllib.py", line 83, in feed
 self.goahead(0)  File "C:\Program Files\python\lib\sgmllib.py", line 104, in
goahead  if i < j: self.handle_data(rawdata[i:j])  File "C:\Program
Files\python\lib\htmllib.py", line 42, in handle_data 
self.formatter.add_flowing_data(data) AttributeError: 'int' object has no
attribute 'add_flowing_data'

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




More information about the Python-list mailing list