close

how to get redirect url using python requests

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about how to get redirect url using python requests in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

how to get redirect url using python requests?

  1. how to get redirect url using python requests?

    r.history is for URLs prior to the final one, so it's only returning your original URL because you were only redirected once.

  2. get redirect url using python requests

    r.history is for URLs prior to the final one, so it's only returning your original URL because you were only redirected once.

Method 1

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.

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read