![在这里插入图片描述](https://img-blog.csdnimg.cn/img_convert/6952051ce1c6db79f8fec9a4dd19fbb5.png#pic_center)
只需要吧这个id替换掉代码中的id就可以了
from lxml import etree
import requests
import json
from concurrent.futures import ThreadPoolExecutor
pool = ThreadPoolExecutor(max_workers=10)
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3741.400 QQBrowser/10.5.3863.400"
}
def download(id,name):
url = f'http://music.163.com/song/media/outer/url?id={id}'
response = requests.get(url=url,headers = headers).content
with open(name+'.mp3','wb') as f:
f.write(response)
print(name,'下载完成')
def get_id(url):
response = requests.get(url=url,headers=headers).text
page_html = etree.HTML(response)
id_list = page_html.xpath('//textarea[@id="song-list-pre-data"]/text()')[0]
for i in json.loads(id_list):
name = i['name']
id = i['id']
author = i['artists'][0]['name']
pool.submit(download,id,name+'-'+author)
pool.shutdown()
if __name__ == '__main__':
url = 'https://music.163.com/discover/toplist?id=3778678'
get_id(url)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)