我无法请求 shopify 的 /products.json 文件中是否提供产品
I cant request if a product is available from the /products.json file of shopify
我正在尝试对补货监控程序进行编程。为此,我想转换 shopify 商店的 .json 文件,但对于可用部分,我总是会收到错误: (
import bs4 as bs
import urllib.request
import discord
from discord.ext import commands
from dhooks import Webhook
import requests
import json
r = requests.get("https://www.antisocialsocialclub.com/products.json")
products = json.loads((r.text))["products"]
for product in products:
print(product["title"])
print(product["tags"])
print(product["published_at"])
print(product["created_at"])
print(product["product_type"])
print(product["available"])
我得到的错误是:
Traceback (most recent call last):
File "/Users/valentinwestermann/Documents/La dieta mediterranea_dhooks.py", line 20, in <module>
print(product["available"])
KeyError: 'available'
JSON 结构与您所期望的不太一样。 available
键位于从 variant
键作为列表返回的项目中。因此,要找到可用性,您必须处理每个变体:
import requests
import json
r = requests.get("https://www.antisocialsocialclub.com/products.json")
products = json.loads((r.text))["products"]
for product in products:
print(product["id"])
print(product["title"])
print(product["tags"])
print(product["published_at"])
print(product["created_at"])
print(product["product_type"])
for variant in product["variants"]:
print(variant['available'])
这是第一个产品输出:
4508425453643
Broken Ankle White Socks
['SS20']
2020-03-27T20:29:52-07:00
2020-03-27T20:29:52-07:00
False
我正在尝试对补货监控程序进行编程。为此,我想转换 shopify 商店的 .json 文件,但对于可用部分,我总是会收到错误: (
import bs4 as bs
import urllib.request
import discord
from discord.ext import commands
from dhooks import Webhook
import requests
import json
r = requests.get("https://www.antisocialsocialclub.com/products.json")
products = json.loads((r.text))["products"]
for product in products:
print(product["title"])
print(product["tags"])
print(product["published_at"])
print(product["created_at"])
print(product["product_type"])
print(product["available"])
我得到的错误是:
Traceback (most recent call last):
File "/Users/valentinwestermann/Documents/La dieta mediterranea_dhooks.py", line 20, in <module>
print(product["available"])
KeyError: 'available'
JSON 结构与您所期望的不太一样。 available
键位于从 variant
键作为列表返回的项目中。因此,要找到可用性,您必须处理每个变体:
import requests
import json
r = requests.get("https://www.antisocialsocialclub.com/products.json")
products = json.loads((r.text))["products"]
for product in products:
print(product["id"])
print(product["title"])
print(product["tags"])
print(product["published_at"])
print(product["created_at"])
print(product["product_type"])
for variant in product["variants"]:
print(variant['available'])
这是第一个产品输出:
4508425453643
Broken Ankle White Socks
['SS20']
2020-03-27T20:29:52-07:00
2020-03-27T20:29:52-07:00
False