Articles


How to get json data from remote url into Python script



Posted bynitheesh,30th Jul 2016

To get json output data from remote ot local website,

Method 1
      Get data from the URL and then call json.loads e.g.

      import urllib, json

      url = "http://maps.googleapis.com/maps/api/geocode/json?address=googleplex&sensor=false"

      response = urllib.urlopen(url)

      data = json.loads(response.read())

      print data

    Method 2

      json_url = urlopen(url)

      data = json.loads(json_url.read())

      print data

 

    Method 3

      check out JSON decoder in the requests library.

        import requests

        r = requests.get('url')

        print r.json()