当前位置:首页 » 《休闲阅读》 » 正文

python---爬取QQ音乐

14 人参与  2024年12月24日 16:02  分类 : 《休闲阅读》  评论

点击全文阅读


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

1.下载包

pip install jsonpath 

2.代码

import osimport timeimport requestsfrom jsonpath import jsonpathdef 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)        # breaksearch_and_download_qq_music("Black Myth wukong")

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

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


点击全文阅读


本文链接:http://m.zhangshiyu.com/post/206236.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新文章

  • 林语熙周晏京(离婚后,老公天天跪求复合全集阅读)最新章节免费在线阅读_《离婚后,老公天天跪求复合全集阅读》最新热门小说 -
  • 顾绫雪嬴政《被始皇读心后,文武百官卷疯了!完结版阅读》完整版免费在线阅读_(顾绫雪嬴政)全集免费阅读 -
  • 情深意长皆成空完整版阅读(沈卿林砚辞)抖音热文_《情深意长皆成空完整版阅读》最新章节免费在线阅读 -
  • 姐姐为暴富重伤傅家金孙后火葬场了全集阅读小说(傅延江瑶)全文免费阅读无弹窗大结局_(姐姐为暴富重伤傅家金孙后火葬场了全集阅读免费阅读全文大结局)最新章节列表_笔趣阁(姐姐为暴富重伤傅家金孙后火葬场了全集阅读) -
  • 乔以诺萧瑾淮(不是你好是我好全集阅读)精彩试读_《不是你好是我好全集阅读》全本阅读 -
  • 白月光双双《重生后我成全老公和白月光,他却急了全集》全文免费阅读无弹窗大结局_(白月光双双)最新章节免费在线阅读 -
  • 苏小枫苏末小说免费笔趣阁_苏小枫苏末小说全章完本大结局
  • 死遁后他疯了最新小说全文阅读_最新免费小说沈轻洲林梦江之雪_完本小说(死遁后他疯了)
  • 免费小说《顾里宋婷婷小岳欧颖倩》已完结(顾里宋婷婷小岳欧颖倩)热门小说大结局全文阅读笔趣阁
  • 侄子为求富贵,变性后全家后悔最新小说_免费小说全文阅读(苏小枫苏末)_侄子为求富贵,变性后全家后悔苏小枫苏末小说推荐完结
  • 最新《沈轻洲林梦江之雪》小说(全集完整新上小说大结局(沈轻洲林梦江之雪))全文阅读笔趣阁
  • 拒绝嫁给姐夫后,我在八零年代暴富了(陈小棠沈正韩)阅读 -

    关于我们 | 我要投稿 | 免责申明

    Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1