Requests 简明教程

Requests - Handling History

您可以通过使用 response.history 获得给定 URL 的历史记录。如果给定的 URL 有任何重定向,则会将重定向存储在历史记录中。

You can get the history of a given URL by using response.history. If the given URL has any redirects, the same will be stored in history.

For history

import requests
getdata = requests.get('http://google.com/')
print(getdata.status_code)
print(getdata.history)

Output

E:\prequests>python makeRequest.py
200
[<Response [301]>]

response.history 属性将包括基于请求完成的响应对象的详细信息。显示的值将从最旧的排序到最新的。 response.history 属性将跟踪对请求的 URL 所做的所有重定向。

The response.history property will have the details of the response objects that were done based on the request. The values present will be sorted from the oldest to the newest ones. The response.history property tracks all the redirection done on the URL requested.