How to get redirect URL using python requests

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 a story, but it’s not, the above URL points to the video, but I can’t get it, will anyone help? thank you

+5
source share
1 answer

To get the resulting URL after the redirect, you can do r.url .

 r = requests.get('http://techtv.mit.edu/videos/1585-music-session-02/download.source') print(r.url) # http://d1baxxa0joomi3.cloudfront.net/2515a9db659b0ab26d869b4ff2dadca9/original.mov 

r.history for urls to the last, so it only returns the original url because you were redirected only once.

+15
source

Source: https://habr.com/ru/post/1245271/


All Articles