QQ⾳乐爬⾍(原创)
cookie。。。
import requests,time
def download_music(name,string1):
string1=string1[0]
# 播放歌曲
url = '113.215.13.161/qq/{}'.format(string1)
headers = {
'Accept-Encoding': "identity;q=1, *;q=0",
'chrome-proxy': "frfr",
'Range': "bytes=0-",
'User-Agent': "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
}
response = (url,headers=headers)
with open('%s.m4a'%name,'wb') as f:
print('正在下载%s.m4a'%name)
f.t)
def get_download_url(songMID):
url = "u.y.qq/cgi-bin/musicu.fcg"
querystring = {"g_tk": "5381", "loginUin": "0", "hostUin": "0", "format": "json", "inCharset": "utf8",
"outCharset": "utf-8", "notice": "0", "platform": "yqq.json", "needNewCode": "0",
"data": '{"req":{"module":"CDN.SrfCdnDispatchServer","method":"GetCdnDispatch","param":{"guid":"8103905332","calltype":0,"userip":""}},"req_0":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"810390533 headers = {
'accept': "application/json, text/javascript, */*; q=0.01",
'accept-encoding': "gzip, deflate, br",
'accept-language': "zh-CN,zh;q=0.9",
'origin': "y.qq",
'referer': "y.qq/portal/player.html",
'user-agent': "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
'cache-control': "no-cache",
'Postman-Token': "b6c72c9a-43b6-4eb4-916e-60c1f9dadb2b"
}
response = quest("GET", url, headers=headers, params=querystring)
json_obj = response.json()
#返回的respone是jsno字符串
list1 = ['req_0','data','midurlinfo']
list2 = py()
for i in list1:
list2 = (i,None)
if not list2:
break
list3 = []
for i in list2:
list3.('purl',None))
return list3#返回值为包含歌曲下载url的list
#返回歌曲名称和songMID
def get_songMID(keyword):
import requests
url = "c.y.qq/soso/fcgi-bin/client_search_cp"
querystring = {"ct": "24", "qqmusic_ver": "1298", "new_json": "1", "remoteplace": "",
"searchid": "42773248656208759", "t": "0", "aggr": "1", "cr": "1", "catZhida": "1", "lossless": "0",
"flag_qc": "0", "p": "1", "n": "10", "w": keyword,
"g_tk": "5381", "loginUin": "0", "hostUin": "0", "format": "json", "inCharset": "utf8",
"outCharset": "utf-8", "notice": "0", "platform": "yqq.json", "needNewCode": "0"}
payload = ""
headers = {
'accept': "application/json, text/javascript, */*; q=0.01",
'accept-encoding': "gzip, deflate, br",
'accept-language': "zh-CN,zh;q=0.9",
'origin': "y.qq",
'referer': "y.qq/portal/search.html",
'user-agent': "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
}
response = quest("GET", url, data=payload, headers=headers, params=querystring)
json_obj = response.json()
list1 = ['data','song','list']
list2 = py()
for i in list1:
list2 = (i,None)
if not list2:
break
# print('---------------------------------------------------------------')
for i in list2:
mid = i.get('mid',None)
name = i.get('name',None)
lyric = i.get('lyric',None)
qqysinger = i.get('singer',None)[0].get('name')
print(mid,name+'_'+singer+'_'+lyric)
#003h3CYS3UxDB4 ⼩酒窝_林俊杰_《爱情睡醒了》电视剧插曲yield mid,name+'_'+singer+'_'+lyric
#最终实现功能:搜索关键字,并下载搜索到的第⼀页结果的所有歌曲for songmid,song_name in get_songMID('⼩酒窝'):
try:
time.sleep(3)
abc = get_download_url(songmid)
time.sleep(3)
download_music(song_name,abc)
# break
except:pass
QQ⾳乐爬⾍代码
发布评论