【问题标题】:Data api, I need to take the value from buys, only data is output, i check dictionary and nothing数据api,我需要从购买中获取价值,只输出数据,我查字典什么都没有
【发布时间】:2022-01-20 04:03:39
【问题描述】:

请帮忙 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]

【问题讨论】:

    标签: python web-scraping scrapy screen-scraping


    【解决方案1】:

    您正在打印字符串“数据”而不是变量本身。

    你需要使用 print(data)

    无论如何要获得购买的价格,您需要像这样更改循环。

    for item in data["data"]["buys"]:
        price = item["price"]
        print(price)
    

    如果您注意到我删除了 print(data),因为它会用您从网络服务获取的所有数据淹没您的屏幕。

    【讨论】:

      猜你喜欢
      • 2023-02-22
      • 2022-01-15
      • 1970-01-01
      • 2013-01-20
      • 2010-12-31
      • 2022-11-23
      • 1970-01-01
      • 2011-11-08
      • 2017-02-13
      相关资源
      最近更新 更多