离散课上没事干,爬网易云音乐吧~

爬取网易云音乐热歌榜

import requests
from bs4 import BeautifulSoup

header = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36 Edg/80.0.361.66',
}
url = "https://music.163.com/discover/toplist?id=3778678"
response = requests.get(url, headers=header)
html = response.content
soup = BeautifulSoup(html, "html.parser")
songs = soup.find("ul", class_="f-hide").select("a")

i = 1

for song in songs:
    song_id = song['href'][9:]
    song_name = song.text
    song_down_url = "http://music.163.com/song/media/outer/url?id=" + song_id + ".mp3"
    print("第 " + str(i) + " 首歌曲:" + song_down_url)
    print("正在下载...")
    response = requests.get(song_down_url, headers=header).content
    f = open(r'F:/Python大作业/网易云音乐/'+song_name + ".mp3", 'wb')  #文件夹位置自己改
    f.write(response)
    f.close()
    print("下载完成.\n\r")
    i = i + 1

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-09 12:23
转人工😡
门口唉提是地铁杀:五次握手了
点赞 评论 收藏
分享
牛客83700679...:简历抄别人的,然后再投,有反馈就是简历不行,没反馈就是学历不行,多投多改只要技术不差机会总会有的
点赞 评论 收藏
分享
风中翠竹:真的真的真的没有kpi。。。面试官是没有任何kpi的,捞是真的想试试看这个行不行,碰碰运气,或者是面试官比较闲现在,没事捞个人看看。kpi算HR那边,但是只有你入职了,kpi才作数,面试是没有的。
双非有机会进大厂吗
点赞 评论 收藏
分享
小叮当411:应该是1-3个月吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务