欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于Python實(shí)現(xiàn)下載網(wǎng)易音樂(lè)代碼實(shí)例

 更新時(shí)間:2020年08月10日 10:38:38   作者:Yi_warmth  
這篇文章主要介紹了基于Python實(shí)現(xiàn)下載網(wǎng)易音樂(lè)代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

代碼如下

# 爬取網(wǎng)易音樂(lè)
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?id=2182968685"
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:\腳本項(xiàng)目\lianxi\MP3\%s.mp3"%name)
  except:
    print("下載失敗")

結(jié)果展示

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論