Answer the question
In order to leave comments, you need to log in
Urllib2 in python: unable to get page, how to go to next page in this case?
I get the page in python like this:
for x in range(1, 10):
response = urllib2.urlopen("http://site.com/id="+str(x))
page = response.read()
Answer the question
In order to leave comments, you need to log in
If it throws an exception - catch it with try\except , then the program will not be interrupted.
You have 2 options:
1. Before sending a get request, send a head request in order to check what code will be returned (in this case, no exception is thrown).
2. Catch the get request dispatch exception as @SolidlSnake said with try/except blocks.
Pretty clear examples of both of these options are given here:
stackoverflow.com/a/16778473
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question