Skip to content
Advertisement

How to detect when a site check redirects to another page using the requests module?

For example, 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, they 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.

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement