批量爬取网易云热歌榜音乐

import requests
import re

**#一、发送网络请求,访问网站**
url = "https://music.163.com/discover/toplist?id=3778678"   #网易云网址,以热歌榜单链接为例
r = requests.get(url)

**#二、解析热歌榜歌曲ID、歌曲名字**
#print(r.text)
#
  • 孤勇者
  • id_name = re.findall('
  • (.*?)
  • ',r.text) #print(id_name) #打印查看网易云歌曲ID、歌曲名字 **#三、批量下载歌曲** for data in id_name: music_id = data[0] music_name = data[1] print(music_name) music_url = "http://music.163.com/song/media/outer/url?id=" + music_id print(music_url) music_data = requests.get(music_url,timeout=10).content with open(f"{music_name}.mp3",'wb') as f: f.write(music_data) print("下载完成!")

    你可能感兴趣的:(python,爬虫)