保存JSON从URL所输出的一个文件 [英] Save JSON outputed from a URL to a file
本文介绍了保存JSON从URL所输出的一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将如何保存JSON通过URL到文件所输出的?
How would I save JSON outputed by an URL to a file?
例如(此<一个href=\"http://search.twitter.com/search.json?q=hi\">http://search.twitter.com/search.json?q=hi)
语言并不重要。
谢谢!
编辑//我怎么会再追加进一步更新EOF?
edit // How would I then append further updates to EOF?
编辑2 //伟大的答案家伙真的,但我接受了我认为是最优雅的人。谢谢! :)
edit 2// Great answers guys really, but I accepted the one I thought was the most elegant. Thanks! :)
推荐答案
这是很容易在任何语言,但其作用机制各不相同。随着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())
这篇关于保存JSON从URL所输出的一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文