我正在尝试转到一个URL,它将在重定向url中返回一个代码字符串。
2-3秒钟后,我被重定向到https://newurl.com/stuffhere?code=97412098512yidfh480b14r
有办法返回新的URL吗?
发布于 2019-04-22 09:22:12
来自官方文件
Response.history列表包含为完成请求而创建的响应对象。列表是从最老的到最近的响应排序的。
下面是一个打印最终URL的URL的示例:
import requests
response = requests.get('http://httpbin.org/redirect/3')
for resp in response.history:
print(resp.url)要获得最终的URL,只需执行以下操作:
print(response.url)https://stackoverflow.com/questions/55792005
复制相似问题