新闻详情

News Information

Python实现简单的小程序免费音乐MP3下载
2024/12/10 11:14:47

#爬虫!不是简单的爬资料数据#一次向网站的请求 点击 登陆 搜索#免费音乐#1.输入一首歌曲的名字 得到了、

#爬虫!不是简单的爬资料数据

#一次向网站的请求 点击 登陆 搜索


#免费音乐

#1.输入一首歌曲的名字 得到了、

#一系列相关歌曲的列表

#2.点击列表中的一个 得到了,(编号)

#这首歌曲的播放界面

#3.点击播放,得到了

# 美妙的音乐


#付费音乐

#1.输入一首歌曲的名字 得到了、

#一系列相关歌曲的列表

#2.点击列表中的一个

#购买播放界面

import re
import requests

input_song_name=input('请输入歌曲名:')

#网址中看到 %xx  URL编码
url3 = f''
res3 = requests.get(url3)
#搜索结果第一个
#contentId = re.findall('"contentId":"(.*?),"', res3.text)[0]
contentId = re.findall('"contentId":"(.*?),"', res3.text)
#print(contentId)

for id in contentId

url2 = f'https://c.musicapp.migu.cn/MIGUM3.0/resource/song/by-contentids/v2.0?contentId={id}'
res2 = requests.get(url2)

copyrightId = re.findall('"copyrightId":"(.*?),"', res2.text)[0]
contentId = re.findall('"contentId":"(.*?),"', res2.text)[0]
#resourceType
albumId = re.findall('"albumId":"(.*?),"', res2.text)[0]
#netType
#toneFlag
songName = re.findall('"songName":"(.*?),"', res2.text)[0]


#请求
wz = {'channel' : '0140210'}
url1 = f'https://c.musicapp.migu.cn/MIGUM3.0/strategy/listen-url/v2.3?copyrightId={copyrightId}&contentId={contentId}&resourceType=2&albumId={albumId}&netType=01&toneFlag=PQ;'
res1 = requests.get(url1, headers=wz)
down_url = re.findall('"url":"(.*?)","',res1.text)[0]
print(res1.text)


url = '歌曲的链接'
res = requests.get(url)
open(f'{songName}.mp3','wb').write(res.content)