网易云音乐爬取

import requests
import os

url= 'https://m701.music.126.net/20211209181850/fdfc634854fc4fa10565ef9fc58d4f7e/jdyyaac/035e/035a/0e0b/4476600da7400f30899a9ace24f37bea.m4a'

headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36',
}


reponse = requests.get(url=url,headers=headers)
# print(reponse)
# reponse_content = reponse.content  ####.text不能识别二进制   需要 content
# reponse_txt = str(reponse_content.decode('gb2312'))




###将request 获取的数据写入到本地

##########创建文件目录,判断文件是否存在
try:
    os.mkdir('./网易云')
except Exception as e:
    print(e)
    
    
suffix_name = os.path.splitext(url)[-1] ###获取后缀名
#print(suffix_name)
with open('5'+suffix_name, 'wb') as f:
f.write(reponse.content)
print('下载成功')