Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so dont bother with any of their useless mail servers here and just use oauth login instead. Thank the nice Russians for causing that. :)

Paste

Pasted as Python by LibertyNews ( 17 years ago )
#!/usr/bin/env python2.6
"""
Get some JSON data from a URL passed on the commandline

Public Domain
"""
import urllib2
import json
import sys


def getJSONPage( url ):
    """
    Get the JSON response from a url
    """
    data = urllib2.urlopen(url).read()
    
    return json.loads(data)


if __name__ == '__main__':
    if len(sys.argv) > 1:
        for url in sys.argv[1:]:
            print "FROM: %s" % (url)
            print getJSONPage(url)
    else:
        print "Usage: %s <URL>" % (sys.argv[0])

 

Revise this Paste

Your Name: Code Language: