Python urllib2 multiple try statement on urlopen()
- by Kura
So, simply I want to be able to run a for across a list of URLs, if one fails then I want to continue on to try the next.
I've tried using the following but sadly it throws and exception if the first URL doesn't work.
servers = ('http://www.google.com', 'http://www.stackoverflow.com')
for server in servers:
try:
u = urllib2.urlopen(server)
except urllib2.URLError:
continue
else:
break
else:
raise
Any ideas?
Thanks in advance.