Reputation: 603
I've noticed that the requests library for Python does not follow certain URL redirects like my browser.
For example, when I do:
response = requests.get('http://www.bbmt.org/', verify=False, allow_redirects=True)
However, in my browser, I am eventually redirected back to http://www.bbmt.org/.
Is there a way to have requests behave like my browser in these scenarios?
Upvotes: 5
Views: 7652
Reputation: 62666
The redirect inside the https://secure.jbs.elsevierhealth.com
is a javascript redirect.
You can see it inside the source-code:
window.location.href = "http://www.bbmt.org/action/consumeSharedSessionAction?SERVER=WZ6myaEXBLHj3ZzqSv9HPw%3D%3D&MAID=IBS8Eq6B1iRWhf2ywTW5pg%3D%3D&JSESSIONID=aaa8eY-zM394XcPptT_Kv&ORIGIN=670572791&RD=RD";
You will need to run javascript in order to do this redirect (and this is something requests do not do).
If you need a solution for this specific redirect, you can parse the content of the response (in python) and take that specific URL
and use it to create a new request.
If you need a general solution - you will need to use a headless browser to do that. You can find more information in this question.
Upvotes: 6