Python 爬虫QQ音乐
生活随笔
收集整理的這篇文章主要介紹了
Python 爬虫QQ音乐
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Python:3.5
歡迎加入學習交流QQ群:657341423
爬取高質量mp3
import requests headers={'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8','Cache-Control':'no-cache','Connection':'keep-alive','Host':'dl.stream.qqmusic.qq.com','Pragma':'no-cache','Upgrade-Insecure-Requests':'1','User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.2717.400 QQBrowser/9.6.11133.400'}url='https://c.y.qq.com/base/fcgi-bin/fcg_music_express_mobile3.fcg?g_tk=1400579671&jsonpCallback=MusicJsonCallback1725281637681917&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq&needNewCode=0&cid=205361747&callback=MusicJsonCallback1725281637681917&uin=0&songmid=003nzgAn0jKPGF&filename=C400003nzgAn0jKPGF.m4a&guid=7286222600' r=requests.get(url,headers=headers) print (r.text) text=r.text.split('(')[1].split(')')[0] import json get_json=json.loads(text) a=get_json['data']['items'][0]['vkey'] print(a) url='http://dl.stream.qqmusic.qq.com/C400003nzgAn0jKPGF.m4a?vkey=%s&guid=7286222600&uin=0&fromtag=66' %(a) r=requests.get(url,headers=headers)f=open('data.m4a','wb') f.write(r.content) f.close() print(r.status_code)參數修改:第一個url是songmid=003nzgAn0jKPGF,filename=C400003nzgAn0jKPGF.m4a
第二個參數是C400003nzgAn0jKPGF.m4a 和vkey
值得注意的是:第一個鏈接loginUin,hostUin和uin要等于第二個uin,
兩者guid要相等
獲取歌單信息
import requests#獲取全部分類歌單的categoryId #https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_tag_conf.fcg?g_tk=5381&jsonpCallback=getPlaylistTags&loginUin=0& # hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq&needNewCode=0#國語歌單的歌單列表信息 #https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg?rnd=0.07499648392820268&g_tk=5381&jsonpCallback=getPlaylist& # loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq&needNewCode=0&categoryId=165&sortId=5&sin=0&ein=29#熱門歌單的歌單列表信息 url= 'https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg?rnd=0.04378599143046411&g_tk=5381&jsonpCallback=getPlaylist&' \'loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq&needNewCode=0&categoryId=10000000&sortId=5&sin=0&ein=29'#categoryId為分類標簽 #sin為開始,ein為結束,這url代表第一頁,30~59代表第二頁 headers={'referer':'https://y.qq.com/portal/playlist.html','user-agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36'}r = requests.get(url,headers=headers) print (r.text)總結
以上是生活随笔為你收集整理的Python 爬虫QQ音乐的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 记2020年第十一届蓝桥杯感想
- 下一篇: python学习 day013打卡 内置