import requests
import json
from bs4 import BeautifulSoup
link = requests.get('https://api.hypixel.net/skyblock/bazaar')
data = link.text
dictionary = json.loads(data)
print(str(dictionary['products']['BROWN_MUSHROOM']['sell_summary']['sellPrice']))
api在api.hypixel.net/skyblock/bazaar/
Sell summary返回最高卖出价列表,而不是平均卖出价。你找错地方了,这就是为什么它会给你一个错误。也许你要找的是这个?
>>> dictionary['products']['BROWN_MUSHROOM']['quick_status']['sellPrice']
18.3
希望这对你有帮助,你没有放弃。
如果没有API响应的示例,我只能说错误:
"TypeError: list indices must be integers or slices, not str"
意味着您正在尝试使用key
从list
获取值,就像它是字典一样。在你的dictionary
值的某个地方,你有一个值列表。