今天废话不多说直接上代码。下载周杰伦所有歌曲。
# 下载周杰伦歌曲
import requests
import re
for i in range(36):
url = f"http://search.kuwo.cn/r.s?all=%E5%91%A8%E6%9D%B0%E4%BC%A6&ft=music&client=kt&cluster=0&pn={i}&rn=10&rformat=json&callback=searchMusicResult&encoding=utf8&vipver=MUSIC_8.0.3.1&"
resp = requests.get(url)
result = resp.text
# print(result.split("=")[1])
obj = re.compile(r".*?DC_TARGETID':'(?P<num>.*?)'.*?'NAME':'(?P<name>.*?)',", re.S)
try:
for item in obj.finditer(result):
num = item.group("num")
name = item.group("name")
down_url = f"http://antiserver.kuwo.cn/anti.s?format=mp3|aac&rid=MUSIC_{num}&response=res&type=convert_url&br=320kmp3&agent=iPhone"
down_music = requests.get(down_url)
with open(f"./music/{name}.mp3", mode="wb") as f:
f.write(down_music.content)
except Exception as e:
print(e)
显示效果总共下载了239首杰伦的歌: