帝王谷资源网 Design By www.wdxyy.com

代码如下

# 爬取网易音乐
import requests
from bs4 import BeautifulSoup
import urllib.request

headers = {"origin": "https://music.163.com",
      "referer": "https://music.163.com/",
      "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 = "http://music.163.com/playlist"
response = requests.get(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 = 'http://music.163.com/song/media/outer/url' + music['href'][5:] + '.mp3'
  musicname = music.text
  list.append(musicUrl)
  list.append(musicname)
  lists.append(list)
for i in lists:
  url = i[0]
  name = i[1]
  try:
    print("正在下载:{}".format(name))
    urllib.request.urlretrieve(url, "D:\脚本项目\lianxi\MP3\%s.mp3"%name)
  except:
    print("下载失败")

结果展示

基于Python实现下载网易音乐代码实例

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
Python,网易音乐,下载

帝王谷资源网 Design By www.wdxyy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
帝王谷资源网 Design By www.wdxyy.com