首页 > 解决方案 > 如何从 Json Url 中获取价值?

问题描述

我想从 json url 中获取 Value (BestPrice),如果它小于 250 - 做点什么!网址 = https://search.roblox.com/catalog/json?Category=2&SortType=2&ResultsPerPage=1

我已经尝试过 Aphid Il 发布我的代码

while True:     




        resp = requests.get(f"https://search.roblox.com/catalog/json?Category=2&SortType=2&ResultsPerPage=1")

        data = json.loads(resp.text)

        P = Aphid.findall(data, ['BestPrice'])
        N = Aphid.findall(data, "Name")
        S = Aphid.findall(data, "Sales")


        print (f"  {N} Tracking {P} R$            Sales - {S}")
        if P < '250':
            print("VALID")

我想得到 BestPrice 明确的数字,如果它小于 250 - 做点什么

标签: pythonjsonpython-3.xweb-scraping

解决方案


将代码的第二部分更改为:

P = data[0]['BestPrice']
N = data[0]['Name']
S = data[0]['Sales']


print (f"  {N} Tracking {P} R$            Sales - {S}")
if P < '250':
    print("VALID")

应该输出

Shaggy Tracking 375 R$            Sales - 2,127,365

推荐阅读