import requests
from urllib.parse import urlencode
def download_music(pageNum):
params = {
'albumId':'6090879',
'pageNum':pageNum,
'sort':'-1',
'pageSize':'30'
}
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36'
}
url = 'https://www.ximalaya.com/revision/play/album?' + urlencode(params)
response = requests.get(url,headers=headers)
data = response.json()['data']
tracksAudioPlays = data['tracksAudioPlay']
for tracksAudioPlay in tracksAudioPlays:
trackName = tracksAudioPlay['trackName']
src = tracksAudioPlay['src']
with open('mp3/{}.mp3'.format(trackName),'wb') as f:
f.write(requests.get(src,headers=headers).content)
print('{}下载完毕'.format(trackName))
if __name__ == '__main__':
for i in range(1,4):
download_music(str(i))