import requests
from lxml import etree
base_url = 'http://music.163.com/song/media/outer/url?id='
url = 'https://music.163.com/discover/toplist'
# url = 'https://music.163.com/playlist?id=2067685777'
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0."
}
request = requests.get(url,headers=headers).text
html = etree.HTML(request)
song_id = html.xpath('//a[contains(@href, "song?id")]/@href')
song_names = html.xpath('//a[contains(@href, "song?id")]/text()')
for song_id,song_name in zip(song_id,song_names) :
song_id = song_id.strip('/song?id=')
if ('$'in song_id) == False:
print(song_name)
mp3_url = base_url + song_id
mp3 = requests.get(mp3_url,headers=headers).content
with open(f'./网易云音乐/{song_name }.mp3','wb') as file :
file.write(mp3)
版权属于:
管理员
作品采用:
《
署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
》许可协议授权
评论 (0)