import requests
import re
songids_url = 'http://music.taihe.com/artist/2517'
response = requests.get(songids_url)
response.encoding = response.apparent_encoding
html = response.text
songids = set(re.findall('a href="/song/(.*?)"',html))
for songid in songids:
url_api = "http://musicapi.taihe.com/v1/restserver/ting?method=baidu.ting.song.playAAC&songid={}".format(songid)
response = requests.get(url_api)
data = response.json()
file_link = data['bitrate']['file_link']
title = data['songinfo']['title']
print(file_link, title)
response = requests.get(file_link)
with open("%s.m4a"%title,mode = 'wb') as f:
f.write(response.content)
Python爬虫——批量爬歌曲
最新推荐文章于 2024-08-02 23:51:11 发布