python - How to pull information from a Json -


i wondering how use requests library pull text field in json? wouldn't need beautiful soup right?

if response indeed json format, can use requests .json() access fields, example this:

import requests  url = 'http://time.jsontest.com/'  r = requests.get(url) # use .json() json response data r.json() {u'date': u'03-28-2015',  u'milliseconds_since_epoch': 1427574682933,  u'time': u'08:31:22 pm'}  # access field r.json()['date'] u'03-28-2015' 

this automatically parse json response python's dictionary:

type(r.json()) dict 

you can read more response.json here.

alternatively use python's json module:

import json  d = json.loads(r.content)  print d['date'] 03-28-2015  type(d) dict 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -