請幫忙提供api,我把所有東西都放在照片中,我需要從購買中獲取價值,但我不明白怎么做,只輸出資料
import requests
import json
def get_depth(limit=50):
response = requests.get(url="...")
with open("depth.txt", "w") as file:
file.write(response.text)
data = requests.get("...").text
data = json.loads(data)
for items in data["data"]["buys"]:
price = items ["price"]
print("data")
print("data")
def main():
print(get_depth())
if __name__ == "__main__":
main()
[my code][https://i.stack.imgur.com/yAQfP.png]
[data][https://i.stack.imgur.com/Po87U.png]
[list][https://i.stack.imgur.com/ObZVM.png]
[result][https://i.stack.imgur.com/lQHIy.png]
uj5u.com熱心網友回復:
您正在列印字串“data”而不是變數本身。
您需要使用列印(資料)
無論如何,要獲得購買的價格,您需要像這樣更改回圈。
for item in data["data"]["buys"]:
price = item["price"]
print(price)
如果您注意到我洗掉了 print(data) ,因為它會用您從網路服務獲取的所有資料淹沒您的螢屏。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/383365.html
