Python批量下载网易云音乐歌曲

网易云音乐真实地址:
http://music.163.com/song/media/outer/url?id= + (歌曲ID) + .mp3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import requests
import urllib
url_list = input ('请粘贴歌单网址:')# 获取榜单网址
gedan_id = url_list.split('id=')[1]# 获取榜单ID
gedan_api = 'http://music.163.com/api/playlist/detail?id=' + gedan_id# 获取歌单API
r = requests.get(gedan_api)
arr = r.json()['result']['tracks'] # json解析
songs = input ('请输入要下载的歌曲数量:')# 输入要下载音乐的数量,1到100。
for i in range(int(songs)):
name = arr[i]['name'] + '.mp3'
if '/' in name:
name = name.split('/')[0] + '.mp3'
link = 'http://music.163.com/song/media/outer/url?id=' + str(arr[i]['id'])+'.mp3'
urllib.request.urlretrieve(link, 'Python批量下载音乐\\' + name) # 提前要创建文件夹
print(str(i+1) + " " + name + ' 下载完成')
print ('歌曲已下载完成!共 %s 首歌曲!'%songs)

代码是从知乎上复制过来稍作修改的,忘记在哪个问题里面了