the api was updated ,now it contains Audiobooks with no "trackName"
Maybe use result.get('trackName', 'NO NAME AVAILABLE) to print all songs names
info=requests.get(site_url,params={'term':'the beatles','country':'us','limit':200})
i=info.json()
for k in range(200):
print(str(k) + "\n " +i['results'][k]['artistName'] + " : " + i['results'][k]['releaseDate'])
Could do this as well
for result in info['results']:
if "trackName" in result:
print(result['trackName'])
Hello, everyone! As API changes, track names may not be indicated and the range of results may vary (let's take 50):
# Homework: extract track names and their release dates
for i in range (50):
result = json.loads(json.dumps(info['results'][i]))
try:
print(result['trackName'])
except:
print('No track name indicated')
try:
print(result['releaseDate'])
except:
print('No release date indicated')
print()
@Vladimir Surovtsev
As the number of results constantly changes - and we'd like to get all of them - it could be beneficial to make the code a bit more flexible seeting the length of the results as the range:
params = {"media": "music", "term":"the beatles", "country": "us", "limit":200}
r = requests.get(base_url, params)
for i in range (len(r.json()['results'])):