• 大小: 0.70KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-05-05
  • 语言: Python
  • 标签: 网易云  音乐  下载  

资源简介

import requests
from lxml import etree

url = 'https://music.163.com/playlist?id=2409342460'
base_url = 'https://music.163.com/song/media/outer/url?id='

html_str = requests.get(url).text

dom = etree.HTML(html_str)
song_ids = dom.xpath('//a[contains(@href,"/song?")]/@href')
song_names = dom.xpath('//a[contains(@href,"/song?")]/text()')

for song_id,song_name in zip(song_ids,song_names):
    count_id = song_id.strip('/song?id=')

    if('$' in count_id) == False:
         mp3_url = base_url count_id '.mp3'
         print(mp3_url)
         
         mp3 = requests.get(mp3_url).content

    str = '%s.mp3'%song_name
    print(str)
    with open(str,'wb') as file:
         file.write(mp3)

资源截图

代码片段和文件信息

import requests
from lxml import etree

url = ‘https://music.163.com/playlist?id=2409342460‘
base_url = ‘https://music.163.com/song/media/outer/url?id=‘

html_str = requests.get(url).text

dom = etree.HTML(html_str)
song_ids = dom.xpath(‘//a[contains(@href“/song?“)]/@href‘)
song_names = dom.xpath(‘//a[contains(@href“/song?“)]/text()‘)

for song

评论

共有 条评论