将从URL输出的JSON保存到文件 [英] Save JSON outputted from a URL to a file

查看:65
本文介绍了将从URL输出的JSON保存到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将URL输出的JSON保存到文件中?

How would I save JSON outputted by an URL to a file?

例如来自Twitter搜索API(此 http://search.twitter.com/search.json?q = hi )

e.g from the Twitter search API (this http://search.twitter.com/search.json?q=hi)

语言并不重要.

edit//然后如何将进一步的更新附加到EOF?

edit // How would I then append further updates to EOF?

edit 2//确实,答案很好,但是我接受了我认为最优雅的答案.

edit 2// Great answers guys really, but I accepted the one I thought was the most elegant.

推荐答案

在任何语言中这都很容易,但是机制各不相同.使用wget和Shell:

This is easy in any language, but the mechanism varies. With wget and a shell:

wget 'http://search.twitter.com/search.json?q=hi' -O hi.json

要附加:

wget 'http://search.twitter.com/search.json?q=hi' -O - >> hi.json

使用Python:

urllib.urlretrieve('http://search.twitter.com/search.json?q=hi', 'hi.json')

要附加:

hi_web = urllib2.urlopen('http://search.twitter.com/search.json?q=hi');
with open('hi.json', 'ab') as hi_file:
  hi_file.write(hi_web.read())

这篇关于将从URL输出的JSON保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆