0

I was wondering if I can get the current url after a redirect from the starting page, done with requests.

For example:

I send the reqeusts to "google.com" that instantanely sends me to "google.com/page-123456", the page number changes everytime. Can I get the "google.com/page-123456" in my script?

With selenium it can be made like this:

import selenium
import time

driver = (...)
driver.get('google.com')
time.sleep(2)
url = driver.current_url

Can be this made in reqeusts / BeautifoulSoup? How? Thanks

Fabix
  • 321
  • 1
  • 2
  • 17
  • 1
    Does this answer your question? [Python Requests library redirect new url](https://stackoverflow.com/questions/20475552/python-requests-library-redirect-new-url) And if you do `r = requests.get('https://google.com')`, then `r.url` is `https://www.google.com/` so that gives you the current URL you were redirected to, if you don't want the full history. – aneroid Jun 23 '21 at 08:54

1 Answers1

1

Try property url of Request object that you can access by response.request:

    import requests
    response=requests.get("https://google.com")
    url=response.request.url
Adam Jenča
  • 582
  • 7
  • 20