tummy.com, ltd.

#!/usr/bin/python
#
#  Given an HTTP URL, display it's HREFs.

import sys
import urllib
import htmllib
import 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()

Contact

Privacy Policy
Copyright © 1995-2003 tummy.com, ltd, All Rights Reserved
5400 Fossil Court North, Fort Collins, Colorado, USA, 80525
Last modified on 2004-06-07
Python programming makes us more efficient.