網易雲簡單案例

JJJhr發表於2024-06-19
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)

執行結果:

相關文章