在我的一个脚本中获得了以下代码:
#
# 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
我想做的是把我在Firefox中加载到脚本中时在URL上看到的{{.....etc.....}}
内容,这样我就可以从中解析出一个值。我已经搜索了大量的内容,但是我还没有找到一个很好的答案,如何将以.json
结尾的URL中的{{...}}
内容真正转换成Python脚本中的对象。
从Python2.X和Python3.X的网页中获取JSON格式的字典:
另请参见:Read and write example for JSON
从URL获取数据,然后调用
json.loads
Python3示例:
Python2示例:
输出结果如下:
我猜您实际上想从URL获取数据:
或者,在requests库中签出JSON decoder。
相关问题 更多 >
编程相关推荐