import sys import urllib import getopt import re try: opts, args = getopt.getopt( sys.argv[1:], "f:u:ap", ["help", "grammar="] ) except getopt.GetoptError: usage() sys.exit( 2 ) f = 'nofilename.txt' for opt, arg in opts: if opt == '-f': f = open( arg, r ) elif opt == "-u": f = urllib.urlopen( arg ) elif opt == '-a': order = 'alphabetical' elif opt == '-p': order = 'pricewise' f = f.read() #print f pattern = 'href="http:' #//www.amazon.com/gp/product/' mo = True while(mo): mo = re.search(pattern, f) print mo #print mo.group(1)