使用 requests python 3.7.0 检查网页的当前 url

Noa*_*ah 4 python python-3.x python-requests

所以我想检查当前的 URL 是否为 example.com (示例),然后如果是,则使用 if 执行以下操作: if current URL == example.com: then print something,但我的问题不是它我不知道如何使用 python 3 的请求来获取当前的 URL。我已经编写了代码,但这与我的要求无关,因为到目前为止我的代码中没有错误。所以我的问题是如何使用 Python 3 的请求获取当前 URL,任何帮助都很棒..谢谢!我到处都找过了,但找不到任何东西。

aka*_*iya 12

有一种财产叫做.url

>>> import requests
>>> url = 'https://www.amazon.com/'
>>> response = requests.get(url)
>>> response.url
u'https://www.amazon.com/'
Run Code Online (Sandbox Code Playgroud)