Anurag Anurag - 1 year ago 105
Python Question

get contents of url in python

import urllib2
response = urllib2.urlopen('')
html =



Problem is: this url will return json output. and i want to read that json file but it is showing error: string indices must be integers, not str.

Answer Source

You need to convert the JSON response to a python structure with the json library (included with Python):

import json

import urllib2
response = urllib2.urlopen('')
data = json.load(response)  # note, no `.read()`, the library handles that

print data['response']
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download