SoFunction
Updated on 2024-12-20

Python download Netease cloud song list songs sample code

Wrote a download script today, for the record

Effect:

Straight to the code:

# NetEase Cloud Download MP3 songs according to the song list links
import requests
from bs4 import BeautifulSoup

def main():
  url = "https://music./#/playlist?id=3136952023" # Playlist address Please change it.
  if '/#/' in url:
    url = ('/#/', '/')
  headers = {
    'Referer': 'http://music./',
    'Host': 'music.',
    'cookie': 'Go to the website and get it yourself, the way to get it is below',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  }

  s = ()
  try:
    response = (url, headers=headers).content
    soup = BeautifulSoup(response, 'lxml')
    lis = list(('ul'))
    fatherlis = ['Song list name:' + str(('h2').string)]
    for i in lis:
      sonlis = []
      (str(len(fatherlis)) + '.')
      ()
      (str(('href'))[str(('href')).find('=') + 1:-1] + str(('href'))[-1])
      (sonlis)
  except:
    print("\n\t song link input error")
    exit('ERROR!')
  format = '{0:<10}\t{1:{3}<10}\t{2:<10}'
  print("surname Cong'{}'I found it in the{}song".format(str(('h2').string), len(fatherlis) - 1))
  print('-------------------------------------------------------------------------------------------------')
  print('Serial number Song name Song link')
  for i in fatherlis:
    if (i) == 0:
      continue
    else:
      print(
        (i[0], i[1], 'http://music./song/media/outer/url?id=' + i[2] + '.mp3', chr(12288)))
      download_music(i[2],i[1])
  print('########################## download complete ##########################')

# Songs to download
def download_music(song_id,song_name):
  file = "./music/" # Path to the file where the music is stored
  wurl = "/163/" # External link address
  song_url = wurl + song_id + ".mp3"
  # Get the hexadecimal code of the song
  song = (song_url).content
  # Get the name of the song
  # Save the document
  with open(file + song_name + '.mp3', 'wb') as f:
    (song)
if __name__ == '__main__':
  main()

How to get a cookie

Log in to Netflix web version https://music./


Just copy and paste it into the code above and start downloading!

This article on Python download NetEase cloud song list songs sample code is introduced to this article, more related to Python download NetEase cloud song list content, please search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!