基于Python实现下载⽹易⾳乐代码实例
代码如下
# 爬取⽹易⾳乐
import requests
from bs4 import BeautifulSoup
quest
headers = {"origin": "music.163",
"referer": "music.163/",
chrome直接下载
"user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36"} url = "music.163/playlist?id=2182968685"
response = (url, headers=headers).content
resp = BeautifulSoup(response, "lxml")
mains = resp.find("ul", {"class": "f-hide"})
lists = []
for music in mains.find_all("a"):
list = []
# 拼装下载地址
musicUrl = 'music.163/song/media/outer/url' + music['href'][5:] + '.mp3'
musicname =
list.append(musicUrl)
list.append(musicname)
lists.append(list)
for i in lists:
url = i[0]
name = i[1]
try:
print("正在下载:{}".format(name))
except:
print("下载失败")
结果展⽰
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。

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