我正在使用以下代碼從 coinbase 獲取 BTC 資料。我只是從教程中復制了這個,但我想知道它是如何作業的。有人可以一步一步解釋嗎?謝謝
import requests # imports the request library
url = "https://api.exchange.coinbase.com/products/BTC-USD/book?level=1" # provides the url from which data will be pulled
headers = {"Accept": "application/json"} # I don't understand the point of this line
response = requests.request("GET", url, headers=headers) # I just don't understand the point of the 'header' part
print(response.text) # This just prints the result
這是上面代碼的結果:
{"bids":[["45890.49","0.02316146",1]],
"asks":[["45896.07","0.03631374",1]],
"sequence":35929645093,
"auction_mode":false,
"auction":null}
我了解所有這些資料,而不是代碼如何獲取它
uj5u.com熱心網友回復:
您的代碼使用額外的 HTTP 標頭發送GET請求:https://api.exchange.coinbase.com/products/BTC-USD/book?level=1
Accept: application/json
這會導致網路服務器以 JSON 格式發送查詢結果,您可以使用response.text
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/455926.html
