r = requests.get('http://techtv.mit.edu/videos/1585-music-session-02/download.source') for i in r.history: print(i.url)
I think it should print out the history, but it doesn't, the above url points to a video, but I cannot get it, anyone help? Thank you
Use Python urllib Library To Get Redirection URL. request module. Define a web page URL, suppose this URL will be redirected when you send a request to it. Get the response object. Get the webserver returned response status code, if the code is 301 then it means the URL has been redirected permanently.
You can have a frontend app under the redirect URI. Then you can run the code you pasted in your browser. You can use javascript to get the query string of the current page (e.g. by calling window. location.search and then splitting the string using & as the delimiter).
Double 301 Redirect This hack still works today. A double 301 redirect allows you to pass the link juice to the final domain without passing any penalty. It's so simple, you might be skeptical, but the proof is in the pudding and I'll be walking you through it with a live example.
To get the resultant URL after you've been redirected, you can do r.url
.
r = requests.get('https://youtu.be/dQw4w9WgXcQ') print(r.url) # https://www.youtube.com/watch?v=dQw4w9WgXcQ&feature=youtu.be
r.history
is for URLs prior to the final one, so it's only returning your original URL because you were only redirected once.
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