在 steam json 中找到一个词并打印
Find a word in a steam json and print
我试图在下面 JSON 中打印 quantity
之后的数字:
app_data : {
quantity: 1,
...
...
}
This is the link where I am trying to print
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"), options=chrome_options)
inv = "https://steamcommunity.com/profiles/76561198404652782/inventory/json/440/2"
with urllib.request.urlopen(inv) as url:
data = json.loads(url.read().decode())
result = data.find('quantity')
print(data, result)
print(data)
也试过 .find() 但没有成功
json.loads()
returns 字典,而字典上没有 find()
方法。此外,请求 returns 是一个嵌套字典,因此直接键查找将不起作用。您可能需要尝试这些早期帖子中建议的内容。
Find all occurrences of a key in nested python dictionaries and lists
您正在搜索一个键,所以只需为其使用一个条件..
if 'quantity' in data:
print data['quantity']
我试图在下面 JSON 中打印 quantity
之后的数字:
app_data : {
quantity: 1,
...
...
}
This is the link where I am trying to print
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"), options=chrome_options)
inv = "https://steamcommunity.com/profiles/76561198404652782/inventory/json/440/2"
with urllib.request.urlopen(inv) as url:
data = json.loads(url.read().decode())
result = data.find('quantity')
print(data, result)
print(data)
也试过 .find() 但没有成功
json.loads()
returns 字典,而字典上没有 find()
方法。此外,请求 returns 是一个嵌套字典,因此直接键查找将不起作用。您可能需要尝试这些早期帖子中建议的内容。
Find all occurrences of a key in nested python dictionaries and lists
您正在搜索一个键,所以只需为其使用一个条件..
if 'quantity' in data:
print data['quantity']