請求 - 處理歷史記錄



透過使用 response.history,可以獲取給定網址的歷史記錄。如果給定的網址有任何重定向,則它們將被儲存在歷史記錄中。

對於歷史記錄

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

輸出

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

response.history 屬性將包含根據請求完成的響應物件詳細資訊。顯示的值將從最舊的值到最新值排序。response.history 屬性跟蹤在所請求的網址上執行的所有重定向。

廣告