# Program to print contents of a URL # It assumes the resource that the URL points to returns # UTF-8 encoded characters # Matt Bishop, MHI 289I, Winter 2018 # import urllib2 # # ask for the URL # try: urlname = raw_input("Please enter the URL: ") except EOFError: print "Bye!" except: print "That's not a valid string. " else: # # got it -- now try to read from the URL # try: webpage = urllib2.urlopen(urlname) except Exception as msg: print "URL retrieval failed!", msg else: # Read from the object, storing the page's contents in 's'. # and print it s = str(webpage.read()) print s