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&notice=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&notice=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&notice=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&notice=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)

猜你喜欢

转载自blog.csdn.net/huangzhang_123/article/details/77839821