我是第一次嘗試使用api,我需要使用被呼叫的資料。當我運行我的腳本時,我得到一個<Response [200]>所以我的代碼是成功的,但是我如何查看和使用被呼叫的資訊。謝謝!
uj5u.com熱心網友回復:
如果這是您請求 api 的方式,
r = requests.get("api")
通過這種方式,您將獲得純文本回應。
print(r.text)
您還可以通過這樣做獲得 json 輸出
print(r.json())
uj5u.com熱心網友回復:
如果您正在使用requests.
response = requests.get("some url")
response.status_code # get the status code
json_response = response.json() # convert response to json
print(json_response) # you can see dictionary-like structure
print(json_response["arbitrary"]) # you can access data just like normal dictionary
這是requests檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/315088.html
上一篇:使用正則運算式從目錄中讀取檔案
下一篇:洗掉換行符但僅在引號之間
