https://superheroapi.com/api/2619421814940190/search/name/Hulk
{
"response": "error",
"error": "character with given name not found"
}
py.user.next
Ну, вот используй
elena211с этого начни
Нужно передать список имен, получить ответ с их статой
elena211ответ есть.https://www.superheroapi.com/api.php/2619421814940190/search/hulk
>>> import urllib.request >>> import json >>> >>> def download_hero(name): ... urlfmt = ('https://www.superheroapi.com' ... '/api/2619421814940190/search/{}') ... url = urlfmt.format(name) ... req = urllib.request.Request(url, headers={'User-Agent': 'Firefox'}) ... with urllib.request.urlopen(req) as data: ... text = data.read() ... out = json.loads(text) ... return out ... >>> def filter_hero(data, name): ... lst = [i for i in data['results'] if i['name'] == name] ... if lst: ... out = lst[0] ... else: ... out = None ... return out ... >>> def get_hero_stat(data): ... out = data['powerstats'] ... return out ... >>> def get_hero_intelligence(data): ... out = data['intelligence'] ... return out ... >>> hulks = download_hero('Hulk') >>> #print(hulks) ... hulk = filter_hero(hulks, 'Hulk') >>> #print(hulk) ... hulk_stat = get_hero_stat(hulk) >>> #print(hulk_stat) ... hulk_intelligence = get_hero_intelligence(hulk_stat) >>> print(hulk_intelligence) 88 >>>