Last answered:

26 Sept 2023

Posted on:

27 Sept 2022

0

the api was updated ,now it contains Audiobooks with no "trackName"

Maybe use result.get('trackName', 'NO NAME AVAILABLE) to print all songs names

4 answers ( 0 marked as helpful)
Posted on:

03 Nov 2022

1

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'])

Posted on:

22 Nov 2022

3

Could do this as well
for result in info['results']:
    if "trackName" in result:
        print(result['trackName'])

Posted on:

22 Jun 2023

0

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()


Posted on:

26 Sept 2023

0

@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'])):

Submit an answer