how can parse entire output takes request.post object , extract "id" content, considering piece of code?
import json import requests api = 'https://www.googleapis.com/urlshortener/v1/url' elem = json.dumps({'longurl':'http://www.longurl..'}) output = requests.post(api,elem, headers = {'content-type':'application/json'})
adding output.text
gives me this:
{ "kind": "urlshortener#url", "id": "http://goo.gl/..", "longurl": "http://www.longurl.." }
now need extract link in id field, tried put content in file , parse strings file.read()
seems not work. ideas?
load dictionary using json
module:
data = json.loads(output.text) print data['id'] # prints http://goo.gl/o5mii
Comments
Post a Comment