What I mean is, if I go to "www.yahoo.com/thispage", and yahoo has set up a filter to redirect /thispage to /thatpage. So whenever someone goes to /thispage, s/he will land on /thatpage.
If I use httplib/requests/urllib, will it know that there was a redirection? What error pages? Some sites redirect user to /errorpage whenever the page cannot be found.
On a Web site, redirection is a technique for moving visitors to a different Web page than the one they request, usually because the page requested is unavailable. Web users often encounter redirection when they visit the Web site of a company whose name has been changed or which has been acquired by another company.
With requests
, you get a listing of any redirects in the .history
attribute of the response object. It returns a Python list. See the documentation for more.
To prevent requests from following redirects use:
r = requests.get('http://www.yahoo.com/thispage', allow_redirects=False)
If it is in indeed a redirect, you can check the redirect target location in r.headers['location'].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With