geft geft - 5 months ago 19
HTTP Question

How do I prevent a python script from being redirected from a specific web page?

For example, I tried getting Python to read the following filtered page

but Python only gets the unfiltered page


The standard library urllib2 normally follows redirects. If retrieving this URL used to work without being redirected, then the site has changed.

Although you can prevent following the redirect within urllib2 (by providing an alternative HTTP handler), I recommend using requests, where you can do:

import requests
r = requests.get(''
                 '&filter-attack-op=1&display=1', allow_redirects=False)

giving you:

<Response [302]>