CodeSnippet:
import urllib2 attempts = 0 while attempts < 3: try: response = urllib2.urlopen("http://example.com", timeout = 5) content = response.read() f = open( "local/index.html", 'w' ) f.write( content ) f.close() break except urllib2.URLError as e: attempts += 1 print type(e)
|