1、一般网易云音乐歌曲的链接地址是形式:http://music.163.com/song/media/outer/url?id=1203045.mp3
(其中需要修改的只是id部分,所以主要工作是获得歌曲的id)
2、网易云音乐·排行榜的网址形式是:https://music.163.com/discover/toplist?id=19723756,只需要修改id号就能爬取不同排行榜的歌曲
MEDIA_ALLOW_REDIRECTS = True
def handle_redirect(self, file_url):
response = requests.head(file_url)
if response.status_code == 302:
file_url = response.headers["Location"]
return file_url
def get_media_requests(self, item, info):
redirect_url = self.handle_redirect(item["file_urls"][0])
yield scrapy.Request(redirect_url)