#!/usr/bin/python
"""
Lezione numero 8
"""
# Esempio di estrazione di HREF
import sys,urllib,htmllib,formatter
class HREFDisplay(htmllib.HTMLParser):
def anchor_bgn(self, href, name, type):
print "Anchor:\thref='%s' name='%s' type='%s'" % ( href, name, type )
def handle_image(self, source, alt, ismap, align, width, height):
print "Image:\tsource='%s' alt='%s'" % ( source, alt )
if len(sys.argv) != 2:
print 'usage: %s <url>' % sys.argv[0]
sys.exit(1)
parser = HREFDisplay(formatter.NullFormatter())
data = urllib.urlopen(sys.argv[1]).read()
parser.feed(data)
parser.close()