Generating JSON files when using URL through Ajax in Python

Viewed 26

I am trying to web-scarp Shazam. Someone already helped me understand that the url that I was passing into Beautiful soup is loaded through Ajax.

I am not to sure how what I need to use to generate the json files from the url's I pass?

I want to generate json files for many countries most shazamed songs.

The url from Shazam is: https://www.shazam.com/charts/top-200/south-africa,

This is the json file generated on the global shazamed songs: https://www.shazam.com/shazam/v3/en-US/US/web/-/tracks/world-chart-world

I am using python 3.

Thanks so much for the assistance

1 Answers

You can query the api directly:

for South africa its: https://www.shazam.com/shazam/v3/en/NO/web/-/tracks/ip-country-chart-ZA?pageSize=200&startFrom=0

and you have to change the part that says ip-country-part-ZA for different countries. If i want charts from Norway i change it to ip-country-part-NO

so here is what i would do:

response = requests.get("https://www.shazam.com/shazam/v3/en/NO/web/-/tracks/ip-country-chart-ZA?pageSize=200&startFrom=0").json()
track_data = response["tracks"]
tracks = [f'{track["title"]} - {track["subtitle"]}' for track in track_data]
Related