网易云简单案例
import requests # 1.获取单张图片 # 找到目标url url = 'https://p1.music.126.net/MSAC3foF-V7L_wXo8GWNag==/109951169698511206.jpg?imageView&quality=89' # 构造请求头字典 headers = { 'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15' } # # 发送请求获取响应 res = requests.get(url, headers=headers) # 获取的是二进制数据 # print(res.content.decode()) with open('网易云.jpg', 'wb') as f: f.write(res.content) # 2.获取单首歌曲 url = 'https://m701.music.126.net/20240619162250/2a07950fea6727766eeced7bf18f2459/jdyyaac/obj/w5rDlsOJwrLDjj7CmsOj/43962335395/0a93/726b/7840/d6a2fd79f7b454856f6cab3537c7f7b7.m4a' res2 = requests.get(url) print(res2.content) with open('网易云.mp3', 'wb') as f: f.write(res2.content) # 获取单个mv url = 'https://vodkgeyttp8.vod.126.net/cloudmusic/NjExMzY4MjI=/04d0a26136439a05da24a074cdc4372b/755fe8321dba18e2a6ecf36885e62537.mp4?wsSecret=897c32263a6b22e84b6d6a294eeda88a&wsTime=1718784535' res3 = requests.get(url) print(res3.content) with open('网易云.mp4', 'wb') as f: f.write(res3.content)
运行结果: