I am analyzing url phishing data, some urls could have several redirections (301, 302).
I can get the final destination and number of redirections using curl
:
curl -Ls -o /dev/null -w "%{num_redirects},%{url_effective}" <url>
Doing the same thing with python requests
:
import requests
r = requests.get(url, allow_redirects=True)
if r.history:
print(f'{len(r.history)},{r.history[-1].url}')
I found that using requests
history
doesn't give me the final destination (although the downloaded content is the same respect to curl
).
For example given the url (this is a legitimate url, I swear) https://ludik.xyz/music
, this is what I got with curl
:
1,https://ludik.herokuapp.com/#/
This is what I got in python:
1,https://ludik.xyz/music
How can I get the final destination after all redirections in python?
The final url is set on the response object:
In [5]: import requests
...:
...: r = requests.get("https://ludik.xyz/music")
In [8]: r.url
Out[8]: 'https://ludik.herokuapp.com/#/'
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