Last active
December 12, 2015 07:08
-
-
Save lambdamusic/4734361 to your computer and use it in GitHub Desktop.
Python Open url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# if you are on the internet you can access the HTML code of a | |
# given web site | |
# using the urlopen() method/function from the module urllib2 | |
import urllib2 | |
urlStr = 'http://www.python.org/' | |
try: | |
fileHandle = urllib2.urlopen(urlStr) | |
str1 = fileHandle.read() | |
fileHandle.close() | |
print '-'*50 | |
print 'HTML code of URL =', urlStr | |
print '-'*50 | |
except IOError: | |
print 'Cannot open URL %s for reading' % urlStr | |
str1 = 'error!' | |
print str1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment