import requests
import re
url = 'https://music.163.com/discover/toplist'
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36'
}
response = requests.get(url=url,headers=headers)
data = (response.text)
listdata = re.findall('<li><a href="/song\?id=(.*?)">(.*?)</a></li>',data)
#print(listdata)
cont=1
for link , title in listdata:
music = f'http://music.163.com/song/media/outer/url?id={link}.mp3'
music_data = requests.get(url=music).content
with open(fr'C:\Users\Administrator\Desktop\歌曲\{title}.mp3','wb' )as f:
f.write(music_data)