python---爬取QQ音乐
创始人
2024-09-25 01:22:23
0

如Cookie为非vip,仅能获取非vip歌曲

1.下载包

pip install jsonpath  

2.代码

import os import time import requests from jsonpath import jsonpath  def search_and_download_qq_music(query_text):      headers = {         'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0',         'Cookie': 'you cookie here'     }      # 请求的链接     # query_text = 'Black Myth wukong'     search_url = rf'https://u.y.qq.com/cgi-bin/musicu.fcg?data={{"comm":{{"g_tk":235530277,"uin":"1152921504916411742","format":"json","inCharset":"utf-8","outCharset":"utf-8","notice":0,"platform":"h5","needNewCode":1,"ct":23,"cv":0}},"req_0":{{"method":"DoSearchForQQMusicDesktop","module":"music.search.SearchCgiService","param":{{"remoteplace":"txt.mqq.all","searchid":"64237725668973550","search_type":0,"query":"{query_text}","page_num":1,"num_per_page":20}}}}}}'      response = requests.get(search_url)     music_list = jsonpath(response.json(), '$..data.body.song.list')[0]     # print(f'music_list: {music_list}')      if not os.path.exists('Q Music'):         os.mkdir('Q Music')      for item in music_list:         music_mid = jsonpath(item, '$.mid')[0]         music_name = jsonpath(item, '$.name')[0]          # print(f'music_name: {music_name}, music_mid: {music_mid}')          music_data_url = rf'https://u.y.qq.com/cgi-bin/musicu.fcg?data={{"comm":{{"cv":4747474,"ct":24,"format":"json","inCharset":"utf-8","outCharset":"utf-8","notice":0,"platform":"yqq.json","needNewCode":1,"uin":"1152921504916411742","g_tk_new_20200303":1849600344,"g_tk":1849600344}},"req_9":{{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{{"guid":"4868259520","songmid":["{music_mid}"],"songtype":[0],"uin":"1152921504916411742","loginflag":1,"platform":"20"}}}}}}'         music_data_response = requests.get(music_data_url)         # print(f'music_data_response: {music_data_response.json()}')          data_info = jsonpath(music_data_response.json(), '$..purl')[0]         # print(f'data_info: {data_info}')          music_url = f'https://dl.stream.qqmusic.qq.com/{data_info}'          music_response = requests.get(music_url, headers=headers)          with open(f'./Q Music/{music_name}.mp3', 'wb') as file:             file.write(music_response.content)          print(f'《{music_name}》下载成功')         print("-" * 20)         time.sleep(0.5)          # break  search_and_download_qq_music("Black Myth wukong") 

如果有所帮助请给个免费的赞吧~有人看才是支撑我写下去的动力!

声明:
本文仅用作学习记录和交流

相关内容

热门资讯

透视总结!wepoker透视功... 透视总结!wepoker透视功能下载(透视)永久脚本辅助软件(详细辅助可靠教程);wepoker透视...
4分钟了解!新悠悠手游辅助,雀... 4分钟了解!新悠悠手游辅助,雀神麻雀充运势有用吗(切实真的是有挂);小薇(透视辅助)致您一封信;亲爱...
透视美元局!aapoker辅助... 透视美元局!aapoker辅助软件合法吗(透视)永久脚本辅助app(详细辅助可靠教程)1、aapok...
第1分钟了解!花城牌舍辅助系统... 第1分钟了解!花城牌舍辅助系统下载,广西老友玩辅助(一直是有挂)所有人都在同一条线上,像星星一样排成...
6分钟了解!欢聚水鱼怎么破解,... 6分钟了解!欢聚水鱼怎么破解,河洛缸次辅助(竟然真的是有挂);1、超多福利:超高返利,海量正版游戏,...
透视科技!wepoker模拟器... 透视科技!wepoker模拟器哪个(透视)永久脚本辅助app(详细辅助必胜教程);1、打开软件启动之...
9分钟了解!八闽状元郎竹间茶馆... 9分钟了解!八闽状元郎竹间茶馆辅助,上品辅助器(都是是真的有挂);1、每一步都需要思考,不同水平的挑...
辅助透视!wepoker私局代... 辅助透视!wepoker私局代打(透视)永久脚本辅助app(详细辅助普及教程);1、完成wepoke...
4分钟了解!广东雀神挂件定制,... 4分钟了解!广东雀神挂件定制,边锋嘉兴红十辅助(切实真的是有挂)1、完成广东雀神挂件定制的残局,帮助...
透视辅助!wepoker模拟器... 透视辅助!wepoker模拟器哪个好用(透视)永久脚本辅助神器(详细辅助科技教程)1、首先打开wep...