Noah
Noah

Reputation: 381

Check current url of webpage using requests python 3.7.0

so I want to check if the current URL is example.com (example) then if it is then use if to do something like this: if current URL == example.com: then print something, but my problem isn't that it's that I don't know how to get current URL using requests with python 3. I have written code , but it's irrelevant to what I'm asking as there's no errors in my code so far. So my question is how to get current URL using requests with Python 3, any help is great.. thanks! I have looked everywhere and can't find anything on it.

Upvotes: 5

Views: 19966

Answers (2)

akash karothiya
akash karothiya

Reputation: 5950

There is property called .url

>>> import requests
>>> url = 'https://www.amazon.com/'
>>> response = requests.get(url)
>>> response.url
u'https://www.amazon.com/'

Upvotes: 14

Cyphall
Cyphall

Reputation: 368

Getting the URL of your response is very simple:

r = requests.get("www.example.com")
print(r.url)

Upvotes: 5

Related Questions