'''getPageFromURL.py Jeff Ondich, 16 Jan 2009 This program gives a brief illustration of how to use the urllib2 module to retrieve files stored on the network. The program accepts an URL as a command-line argument, retrieves the text of the file specified by that URL, and prints the text to standard output. ''' import sys import urllib2 if len(sys.argv) == 1: sys.stderr.write('Usage: %s url\n' % sys.argv[0]) sys.exit(1) url = sys.argv[1] try: request = urllib2.Request(url) response = urllib2.urlopen(request) pageText = response.read() print pageText except Exception, e: sys.stderr.write('Trouble retrieving %s.\n' % url) sys.stderr.write(' %s\n' % e)