【问题标题】:How Can I scrape Value From Json Url?如何从 Json Url 中获取价值?
【发布时间】:2019-10-31 10:15:21
【问题描述】:

我想从 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 - 做某事

【问题讨论】:

    标签: python json python-3.x web-scraping


    【解决方案1】:

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

    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
    

    【讨论】:

      猜你喜欢
      • 2023-03-03
      • 2021-12-18
      • 2013-09-27
      • 1970-01-01
      • 2013-04-11
      • 1970-01-01
      • 1970-01-01
      • 2017-08-18
      • 2021-05-26
      相关资源
      最近更新 更多