在我的一个脚本中得到以下代码:
#
# url is defined above.
#
jsonurl = urlopen(url)
#
# While trying to debug, I put this in:
#
print jsonurl
#
# Was hoping text would contain the actual json crap from the URL, but seems not...
#
text = json.loads(jsonurl)
print text
我想要做的是获取 {{.....etc.....}}
当我在 Firefox 中将其加载到我的脚本中时在 URL 上看到的内容,以便我可以从中解析出一个值。我已经用谷歌搜索了很多,但我还没有找到一个很好的答案,即如何从以 .json
结尾的 URL 中实际获取 {{...}}
内容到 Python 脚本中的对象中。
原文由 Chris B 发布,翻译遵循 CC BY-SA 4.0 许可协议
从 URL 获取数据然后调用
json.loads
例如Python3 示例:
Python2 示例:
输出将导致类似这样的结果: