python - How can i get multiple layer in JSON format -


i'm using pyhton3.4.1.

i'm using google custom search.

i want link diplay typeerror: string indices must integers.

below code , json format.

from urllib.request import urlopen import json u = urlopen('https://www.googleapis.com/customsearch/v1?key=aizasyc3jpmwo3ieifw1vnrvol3ms3kse_gmrvo&cx=010407088344546736418:onjj7gscy2g&q=lol&num=10') resp = json.loads(u.read().decode('utf-8')) link in resp:   k in link['item']:     print(k['link']) 

and json fomat below.

 "items": [ { "kind": "customsearch#result", "title": "league of legends", "htmltitle": "<b>league of legends</b>", "link": "http://leagueoflegends.com/", "displaylink": "leagueoflegends.com", "snippet": "official site. features, media, screenshots, faqs, , forums.", "htmlsnippet": "official site. features, media, screenshots, faqs, ,   forums.", "cacheid": "gcrd1wy5e3qj", "formattedurl": "leagueoflegends.com/", "htmlformattedurl": "<b>leagueoflegends</b>.com/", "pagemap": { "cse_image": [  {   "src": "http://na.leagueoflegends.com/sites/default/files/styles/wide_small/public/upload/pool_party_201_splash_1920.jpg?itok=qgxfrikl"  } ], "cse_thumbnail": [  {   "width": "256",   "height": "144",   "src": "https://encrypted-tbn0.gstatic.com/images?q=tbn:and9gcsvycglnn9a7n13rjwbpvsnemh-mbqzc6otkcjgeok-6c1dkcmp6xiumtxg"  } ], 

change last 3 lines to:

for item in resp['items']:     print(item['link']) 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -