python⾳乐下载演⽰源代码
import requests
import re
api = 'music.taihe/search?'
header = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'
}
data = {
'key': '薛之谦'
}
response = (api, params=data, headers=header)
html =
sids = re.findall(r'data-playdata="(.+?)"', 'html', re.S)
print(sids)
da1 = re.findall(r'\d+', sids[0])
print(da1)
for i in da1:
url = r'music.taihe/data/tingapi/v1/restserver/ting?method=baidu.ting.ugccenter.checkFollRedPoint×tamp={}¶m=qTPtZ4RJPty%2BSRTk9J2nlD%2FpisYR9p8jVnkaoeV5DaI%3D&sign=bf2bac06f185709890e3d6abf56ad998&from=web'. response = (url)
data =
print(data)
# 第⼀种提取⽅式
data1 = re.findall(r'\((.*)\)', data)[0]
print(data1)
# JSON 格式转换
data2 = json.loads(data1)
mp3_name =data2['songinfo']['title']
chrome直接下载mp3_url = data2['baitrate']['file_link']
print(mp3_name)
print(mp3_url)
response = (mp3_url)
with open(r'./mp3/%s.mp3'%mp3_name, 'wb') as f:
f.t)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。