我正在尝试创建一个Python脚本,该脚本可以获取某人的Steam库存中的项目列表。我目前有这个代码:
#!/usr/bin/python
import urllib2
import json
def getInventory(steamid):
data = urllib2.urlopen('http://steamcommunity.com/profiles/'+steamid+'/inventory/json/730/2')
json_data = json.loads(data)
print 'Success: %s' % json_data['success']
for v in json_data['rgDescriptions']:
print 'Item: ' + v['name']
print('Done!')
return
getInventory('76561197988445370');
但它不会输出'Success: True'
和'Done!'
以外的任何内容。有人可以帮助我让这个工作吗?
答案 0 :(得分:1)
对于任何想知道如何立即执行此操作的人,这在2019年对我有效:
#!/usr/bin/python
import json
import requests
def getInventory(steamid):
data = requests.get(
"https://steamcommunity.com/id/{}/inventory/json/730/2?l=english&count=5000".format(steamid))
json_data = json.loads(data.text)
descriptions = json_data["rgDescriptions"]
print([(descriptions[item]["name"], getItemAmount(descriptions[item]["classid"], json_data)) for item in descriptions])
def getItemAmount(classid, json_data):
inventory = json_data["rgInventory"]
count = 0
for item in inventory:
if inventory[item]["classid"] == classid:
count += 1
return count
新端点是https://steamcommunity.com/id/STEAMID/inventory/json/730/2
答案 1 :(得分:0)
以下代码适用于我:
migrate