精华内容
下载资源
问答
  • python爬取QQ音乐

    2021-06-08 17:23:28
    爬虫爬取QQ音乐 import json import os import requests w=str(input('输入歌名:')) if not os.path.exists('./QQ音乐'): os.mkdir('./QQ音乐') url = f"https://c.y.qq.com/soso/fcgi-bin/client_search_cp?" ...

    爬虫爬取QQ音乐

    import json
    import os
    import requests
    w=str(input('输入歌名:'))
    if not os.path.exists('./QQ音乐'):
        os.mkdir('./QQ音乐')
    url = f"https://c.y.qq.com/soso/fcgi-bin/client_search_cp?"
    param={
    'ct':'24',
    'qqmusic_ver':'1298',
    'new_json':'1',
    'remoteplace':'txt.yqq.top',
    'searchid':'61087599084075221',
    't':'0',
    'aggr':'1',
    'cr':'1',
    'catZhida':'1',
    'lossless':'0',
    'flag_qc':'0',
    'p':'1',
    'n':'10',
    'w':w,
    '_':'1623141792983',
    'cv':'4747474',
    'format':'json',
    'inCharset':'utf-8',
    'outCharset':'utf-8',
    'notice':'0',
    'platform':'yqq.json',
    'needNewCode':'0',
    'uin':'0',
    'g_tk_new_20200303':'17197024',
    'g_tk':'17197024',
    'hostUin':'0',
    'loginUin':'0',
    }
    response = requests.get(url=url,params=param).json()
    print('---开始获取---')
    
    cv_id=response['data']['song']['list'][0]['mid']
    title=response['data']['song']['list'][0]['title']
    header={
    'cookie':'pgv_pvid=6923664120; RK=0sSZFEUKVy; ptcz=86bbd55a704e7b99fb161db1f043c340b26998788050ddef4740a2e7255e0ef0; ts_uid=7141101048; _ga=GA1.2.1239448856.1621763416; pac_uid=0_b838840b8af3c; _tc_unionid=02bb6f2a-9d72-4295-933d-46d698db7bb8; fqm_pvqid=a154c562-e8a1-41c6-b9e3-90854544ce29; euin=oKoz7iclNeEFNv**; tmeLoginType=2; psrf_musickey_createtime=1623075815; psrf_access_token_expiresAt=1630851815; qqmusic_key=Q_H_L_2S_A_260eKOpCJD5BIdSYeOxulHYWAXsug5ImnoYJofDkcL0_FZ1bf7k3hojh6F; pgv_info=ssid=s4212472504; fqm_sessionid=38693813-fad4-4b3c-9037-6a759b8951aa; ts_refer=i.y.qq.com/; ts_last=y.qq.com/n/ryqq/player',
    'origin':'https://y.qq.com',
    'pragma':'no-cache',
    'referer':'https://y.qq.com/',
    'sec-ch-ua':'" Not;A Brand";v="99", "Microsoft Edge";v="91", "Chromium";v="91"',
    'sec-ch-ua-mobile':'?0',
    'sec-fetch-dest':'empty',
    'sec-fetch-mode':'cors',
    'sec-fetch-site':'same-site',
    'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36 Edg/91.0.864.41',
    'authority': 'u.y.qq.com',
    'method': 'POST',
    'path': '/cgi-bin/musics.fcg?_=1623137897727&sign=zzaw8qvbhqe3pmxnm52b3b2951a63aef215b6b15f90a78a17',
    'scheme': 'https',
    }
    mus_url='https://u.y.qq.com/cgi-bin/musicu.fcg?“”&g_tk=352421221&jsonpCallback=getplaysongvkey7281977218930408&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq&needNewCode=0&data={"req_1":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"4313582267","songmid":["%s"],"songtype":[0,0,0,0,0],"uin":"0","loginflag":1,"platform":"20"}}}'%cv_id
    print('---获取成功---')
    res=requests.get(url=mus_url,headers=header).json()
    file_name=res['req_1']['data']['midurlinfo'][0]['filename']
    purl=res['req_1']['data']['midurlinfo'][0]['purl']
    if len(purl)==0:
        cv_id = response['data']['song']['list'][1]['mid']
        title = response['data']['song']['list'][1]['title']
        mus_url = 'https://u.y.qq.com/cgi-bin/musicu.fcg?“”&g_tk=352421221&jsonpCallback=getplaysongvkey7281977218930408&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq&needNewCode=0&data={"req_1":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"4313582267","songmid":["%s"],"songtype":[0,0,0,0,0],"uin":"0","loginflag":1,"platform":"20"}}}' % cv_id
        res = requests.get(url=mus_url, headers=header).json()
        file_name = res['req_1']['data']['midurlinfo'][0]['filename']
        purl = res['req_1']['data']['midurlinfo'][0]['purl']
    else:
        pass
    full_url="http://ws.stream.qqmusic.qq.com/"+file_name+'/'+purl
    print('开始下载')
    headers={
    'Connection':'keep-alive',
    'Cookie':'pgv_pvid=6923664120; RK=0sSZFEUKVy; ptcz=86bbd55a704e7b99fb161db1f043c340b26998788050ddef4740a2e7255e0ef0; _ga=GA1.2.1239448856.1621763416; pac_uid=0_b838840b8af3c; _tc_unionid=02bb6f2a-9d72-4295-933d-46d698db7bb8; fqm_pvqid=a154c562-e8a1-41c6-b9e3-90854544ce29; euin=oKoz7iclNeEFNv**; tmeLoginType=2; pgv_info=ssid=s4212472504; fqm_sessionid=38693813-fad4-4b3c-9037-6a759b8951aa; _qpsvr_localtk=0.5195022146245027; psrf_musickey_createtime=1623138971; qqmusic_key=Q_H_L_2if8-260eSliOE22c5FqwIR3A-FZhVfXdqQ1qkOwp-7yNnOI0Su_lQJI_Vw2a17; psrf_access_token_expiresAt=1630914971',
    'Host':'ws.stream.qqmusic.qq.com',
    'Pragma':'no-cache',
    'Upgrade-Insecure-Requests':'1',
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36 Edg/91.0.864.41',
    }
    
    music=requests.get(url=full_url,headers=headers).content
    m=title[0:4] +'.mp3'
    print(m)
    path='./QQ音乐/'+m
    with open(path,'wb') as  f:
        f.write(music)
        print('下载成功!!!!')
    
    
    
    
    
    展开全文
  • python爬取qq音乐

    千次阅读 2019-09-11 17:32:27
    爬取网页版的音乐可以使用抓包工具也可以直接使用谷歌浏览器的开发者调试工具分析地址 下面使用开发者调试工具分析数据 从搜索开始随便输入一个歌曲名到搜索框 可以看到有很多请求,一般我们需要的都是ajax...

    爬取网页版的音乐可以使用抓包工具也可以直接使用谷歌浏览器的开发者调试工具分析地址

    下面使用开发者调试工具分析数据

    从搜索开始随便输入一个歌曲名到搜索框

     

    可以看到有很多请求,一般我们需要的都是ajax请求所以切换到XHR选项:

    会有很多请求,一般请求以json数据返回

    寻找返回的json数据

    挨个点一下看看response或者preview一般来说返回的json数据都比较多的才能获取到有用的信息,

     

    这条返回的比较长复制链接打开看看

     

    经过分心没有有用的信息,经过一番分析找到了这个链接:https://c.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&new_json=1&remoteplace=txt.yqq.song&searchid=70950360097159007&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=1&n=10&w=%E8%99%9A%E8%99%9A%E5%AE%9E%E5%AE%9E&g_tk=5381&loginUin=1043619528&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0

     

     

    里面有音乐的一些参数正是需要的

    来分析下这个链接

     

    其他参数经过尝试都是固定的

    打开详细页面

     

    找到如下又有效地址:

    歌词地址:https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_yqq.fcg?nobase64=1&musicid=110532&-=jsonp1&g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0

    复制后打开出现如下报错:

     

    试试用python模拟请求看看

    可以打开:

    模拟请求代码:

     

    import requests
    import ssl
    ssl_context = ssl._create_unverified_context
    def get_request(url):
        header = {
                    'Connection': "keep-alive",
                    'Pragma': "no-cache",
                    'Cache-Control': "no-cache",
                    'User-Agent': "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) "
                                  "Chrome/72.0.3626.119 Safari/537.36",
                    'Accept': "*/*",
                    'Referer': url,
                    'Accept-Encoding': "gzip, deflate, sdch, br",
                    'Accept-Language': "zh-CN,zh;q=0.8",
                    'cache-control': "no-cache",
                }
        return requests.get(url, headers=header)
    
    url ='https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_yqq.fcg?nobase64=1&musicid=110532&-=jsonp1&g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0'
    res = get_request(url)
    print(res.text)

    评论地址:https://c.y.qq.com/base/fcgi-bin/fcg_global_comment_h5.fcg?g_tk=5381&loginUin=1043619528&hostUin=0&format=json&inCharset=utf8&outCharset=GB2312&notice=0&platform=yqq.json&needNewCode=0&cid=205360772&reqtype=2&biztype=1&topid=110532&cmd=8&needmusiccrit=0&pagenum=0&pagesize=25&lasthotcommentid=&domain=qq.com&ct=24&cv=10101010

     

     

    下面开始播放,点击播放就会到播放页面,对播放页面进行分析找到如下地址:

     

     

    https://u.y.qq.com/cgi-bin/musicu.fcg?-=getplaysongvkey675913044284586&g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0&data=%7B%22req%22%3A%7B%22module%22%3A%22CDN.SrfCdnDispatchServer%22%2C%22method%22%3A%22GetCdnDispatch%22%2C%22param%22%3A%7B%22guid%22%3A%228348972662%22%2C%22calltype%22%3A0%2C%22userip%22%3A%22%22%7D%7D%2C%22req_0%22%3A%7B%22module%22%3A%22vkey.GetVkeyServer%22%2C%22method%22%3A%22CgiGetVkey%22%2C%22param%22%3A%7B%22guid%22%3A%228348972662%22%2C%22songmid%22%3A%5B%22004HSDX22cYJlt%22%5D%2C%22songtype%22%3A%5B0%5D%2C%22uin%22%3A%221043619528%22%2C%22loginflag%22%3A1%2C%22platform%22%3A%2220%22%7D%7D%2C%22comm%22%3A%7B%22uin%22%3A1043619528%2C%22format%22%3A%22json%22%2C%22ct%22%3A24%2C%22cv%22%3A0%7D%7D

     

    数据被url编码了使用站长工具解析一下:

    http://tool.chinaz.com/tools/urlencode.aspx

    解析后如下:

    https://u.y.qq.com/cgi-bin/musicu.fcg?-=getplaysongvkey675913044284586&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":"8348972662","calltype":0,"userip":""}},"req_0":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"8348972662","songmid":["004HSDX22cYJlt"],"songtype":[0],"uin":"1043619528","loginflag":1,"platform":"20"}},"comm":{"uin":1043619528,"format":"json","ct":24,"cv":0}}

    经过分析发现只要获取songmid即可而songmid就是详细页的音乐id编码

     

    所以直接提取这段信息即可

    通过搜索得到的信息也有这个信息

     

    播放地址进过实验发现为sip地址加purl

     

     

    其他的地址经过测试都不能得到播放地址

    请求地址http://ws.stream.qqmusic.qq.com/C40000112DdN4Kn7CA.m4a?guid=8348972662&vkey=D6CAC5EFFC242688DBD0B536E70B4D9129E05E35AA80F85870C196921EA7D1ACB6566301450C67F516D644F20E3843BC8536B4B65A458629&uin=7880&fromtag=66

    得到如下播放界面

     

    代码实现如下:

    #-*- coding: utf-8 -*-
    import requests
    import json
    import urllib
    import sys,os
    import re
    from bs4 import BeautifulSoup
    class Music_tx():
        def __init__(self):
            self.header = {
                'Connection': "keep-alive",
                'Pragma': "no-cache",
                'Cache-Control': "no-cache",
                'User-Agent': "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) "
                              "Chrome/72.0.3626.119 Safari/537.36",
                'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
                'Referer': "https://y.qq.com",
                'Accept-Encoding': "gzip, deflate, br",
                'Accept-Language': "zh-CN,zh;q=0.9",
                'cache-control': "no-cache",
            }
    
        # 显示下载进度
        def _progress(self, block_num, block_size, total_size):
            '''回调函数
               @block_num: 已经下载的数据块
               @block_size: 数据块的大小
               @total_size: 远程文件的大小
            '''
            sys.stdout.write('\r>> 已下载: %.1f%%' % (int(block_num * block_size) / int(total_size) * 100.0))
            sys.stdout.flush()
        #通过json接口搜索音乐
        def search_music(self,keyword,num = 2,page = 1,file_path = None):
            url = 'https://c.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&new_json=1&remoteplace=txt.yqq.song&searchid=62240638881390953&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p='+str(page)+'&n='+str(num)+'&w='+str(keyword)+'&g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0'
            response= requests.get(url, headers=self.header)
            music_data = response.text
            json_music_data = json.loads(music_data)
            music_list = json_music_data['data']['song']['list']
            song_mids = []
            song_titles = []
            song_singers = []
            num = 0
            if not file_path:
                file_path = os.path.dirname(os.path.abspath(__file__)) + '\\'
                if not os.path.isdir(file_path + 'mp3'):
                    os.mkdir(file_path + 'mp3')
                file_path = os.path.dirname(os.path.abspath(__file__)) + '\\mp3\\'
            for data in music_list:
                try:
                    song_mids.append(data['mid'])
                    song_titles.append(data['title'])
                    song_singers.append(data['singer'][0]['name'])
                    print('正在下载:', data['title'], '......')
                    get_url = 'https://u.y.qq.com/cgi-bin/musicu.fcg?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":"8348972662","calltype":0,"userip":""}},"req_0":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"8348972662","songmid":["'+data['mid']+'"],"songtype":[1],"uin":"0","loginflag":1,"platform":"20"}},"comm":{"uin":0,"format":"json","ct":24,"cv":0}}'
                    response = requests.get(get_url)
                    sip = json.loads(response.text)['req']['data']['sip'][0]
                    purl = json.loads(response.text)['req_0']['data']['midurlinfo'][0]['purl']
                    real_url = sip + purl
                    if os.path.isfile(file_path + data['title']+'-'+ data['singer'][0]['name'] + '.m4a'):
                        num += 1
                        path = file_path + data['title'] + '-' + data['singer'][0]['name'] + str(num) + '.m4a'
                    else:
                        path = file_path + data['title'] + '-' + data['singer'][0]['name'] + '.m4a'
                    try:
                        urllib.request.urlretrieve(real_url,path,reporthook=self._progress)
                        print('下载' + data['title'] + '成功')
                    except Exception:
                        print('下载' +data['title'] + '失败')
                        print(str(Exception))
                except:
                    print('wrong')
            print("下载完成")
    
        #获取播放地址
        def get_play_url(self,songid,strMediaMid):
            url = 'https://c.y.qq.com/base/fcgi-bin/fcg_music_express_mobile3.fcg?&jsonpCallback=MusicJsonCallback&cid=205361747&songmid=' +\
                   songid+ '&filename=C400' +strMediaMid+ '.m4a&guid=6612300644'
            # 获取返回文件并解析得到vkey
            response = requests.get(url)
            json_data = json.loads(response.text)
            vkey = json_data['data']['items'][0]['vkey']
            real_url = 'http://isure.stream.qqmusic.qq.com/C400' + strMediaMid + '.m4a?vkey=' + vkey + '&guid=6612300644&uin=0&fromtag=66'
            #print(real_url)
            return real_url
        #通过网址直接下载
        def down_music(self,url,file_path = None):
            t = re.compile('\w+')
            songmid = t.findall(url)[7]
            get_url = 'https://u.y.qq.com/cgi-bin/musicu.fcg?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":"8348972662","calltype":0,"userip":""}},"req_0":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"8348972662","songmid":["'+songmid+'"],"songtype":[1],"uin":"0","loginflag":1,"platform":"20"}},"comm":{"uin":0,"format":"json","ct":24,"cv":0}}'
            response = requests.get(get_url)
            sip = json.loads(response.text)['req']['data']['sip'][0]
            purl = json.loads(response.text)['req_0']['data']['midurlinfo'][0]['purl']
            real_url = sip + purl
            res = requests.get(url)
            soup = BeautifulSoup(res.content, 'html.parser')
            title = soup.find('h1', attrs={'class': 'data__name_txt'}).text
            singer = (soup.find('div', attrs={'class': 'data__singer'}).text).replace('\n','')
            num = 0
            if not file_path:
                file_path = os.path.dirname(os.path.abspath(__file__)) + '\\'
                if not os.path.isdir(file_path + 'mp3'):
                    os.mkdir(file_path + 'mp3')
                file_path = os.path.dirname(os.path.abspath(__file__)) + '\\mp3\\'
            if os.path.isfile(file_path + title + '-' + singer + '.m4a'):
                num += 1
                path = file_path + title + '-' + singer + str(num) + '.m4a'
            else:
                path = file_path + title + '-' + singer + '.m4a'
            try:
                urllib.request.urlretrieve(real_url, path, reporthook=self._progress)
                print('下载' + title + '成功')
            except Exception:
                print('下载' + title + '失败')
    
    
    if __name__ == '__main__':
        qq_music = Music_tx()
        # url = 'https://y.qq.com/n/yqq/song/0020stYG1RLye8.html'
        # qq_music.down_music(url)#通过网址下载
        qq_music.search_music('虚虚实实')#通过搜索下载

     

    用到的接口:

    搜索接口

    https://c.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&new_json=1&remoteplace=txt.yqq.song&searchid=62240638881390953&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p='+str(page)+'&n='+str(num)+'&w='+str(keyword)+'&g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0

     

    播放接口:

    https://u.y.qq.com/cgi-bin/musicu.fcg?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":"8348972662","calltype":0,"userip":""}},"req_0":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"8348972662","songmid":["'+songmid+'"],"songtype":[1],"uin":"0","loginflag":1,"platform":"20"}},"comm":{"uin":0,"format":"json","ct":24,"cv":0}}

    找到的接口有可能过几天甚至第二天就不能用了这个很正常,只能重新分析

    还有一个接口是网上找到的拼接起来有点麻烦下一篇文章分析一下。

    下一篇地址:https://blog.csdn.net/XBODHX/article/details/100743772

     

     

     

     

     

     

     

    展开全文
  • Python爬取QQ音乐

    千次阅读 2019-03-03 13:47:59
    今天写了qq音乐爬虫供大家参考。 大佬不要喷。我知道有点菜。 import random import urllib import urllib.request import requests import json USER_AGENTS = [ "Mozilla/5.0 (Windows NT 6.1; WOW64) ...

    今天写了qq音乐爬虫供大家参考。
    大佬不要喷。我知道有点菜。
     

    import random
    import urllib
    import urllib.request
    import requests
    import json

    USER_AGENTS = [
    "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36",
    "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36",
    "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.26 Safari/537.36 Core/1.63.5509.400 QQBrowser/10.1.1601.400"
    ]

    随机头

    def random_header():
    headers = {
    "User-Agent": random.choice(USER_AGENTS)
    }
    return headers

    搜索歌曲名

    def search_music_name():
    return input("请输入歌曲名:")

    data_search = {
    "ct": "24",
    "qqmusic_ver": "1298",
    "new_json": "1",
    'remoteplace': 'txt.yqq.center',
    "searchid": "71552798001734829",
    "t": "0",
    "aggr": "1",
    "cr": "1",
    "catZhIDA": "1",
    "lossless": "0",
    "flag_qc": "1",
    "p": "1",
    "n": "50",
    "w": search_music_name(),
    "g_tk": "5381",
    "loginUin": "0",
    "hostUin": "0",
    "format": "jsonp",
    "inCharset": " utf8",
    "outCharset": " utf-8",
    "notice": " 0",
    'platform': 'yqq',
    "needNewCode": " 0"
    }
    url_search = r"http://c.y.qq.com/soso/fcgi-bin/client_search_cp?"
    search_api = requests.get(url_search, params=data_search, headers=random_header())
    search_api = search_api.text.replace("callback(", '')[:-1]
    music_info = json.loads(search_api)
    music_list = music_info["data"]["song"]["list"]

    获取歌曲时长

    def get_sing_time(time):
    m = time // 60
    s = time % 60
    return str(m) + ":" + str(s)

    k = 0
    for index in range(len(music_list)):
    sing_info = music_list[index]['name']
    singer_name = music_list[index]["singer"][0]["name"]
    albumname = music_list[index]["album"]["name"]
    sing_time = music_list[index]["interval"]
    sing_time = get_sing_time(sing_time)
    k += 1
    print(str(k) + " : " + sing_info + "   歌手:" + singer_name + "     专辑:" + albumname + "   时长:" + sing_time)
    num = int(input('请选择你要下载的歌曲:'))

    songmid = music_list[num - 1]["file"]["media_mid"]
    singName=music_list[num-1]["name"]
    singer_name = music_list[num-1]["singer"][0]["name"]

    获取真正的key

    key_url = 'https://u.y.qq.com/cgi-bin/musicu.fcg?callback=getplaysongvkey626277975566637&g_tk=5381&jsonpCallback=getplaysongvkey626277975566637&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq&needNewCode=0&data={"req":{"module":"CDN.SrfCdnDispatchServer","method":"GetCdnDispatch","param":{"guid":"552068528","calltype":0,"userip":""}},"req_0":{"module":"vkey.GetVkeyServer","method":"CgiGetVkey","param":{"guid":"552068528","songmid":["'+songmid+'"],"songtype":[0],"uin":"0","loginflag":1,"platform":"20"}},"comm":{"uin":0,"format":"json","ct":20,"cv":0}}'

    key = requests.get(key_url)
    key_api = key.text.replace(r"getplaysongvkey626277975566637(", "")[:-1]
    key_api = json.loads(key_api)
    vkey = key_api["req_0"]["data"]["midurlinfo"][0]["vkey"]
    url_ape = "http://183.222.96.19/amobile.music.tc.qq.com/A000"+songmid+".ape?guid=552068528&vkey="+vkey+"&uin=0&fromtag=91&.ape"
    url_flac = "http://183.222.96.19/amobile.music.tc.qq.com/F000"+songmid+".flac?guid=552068528&vkey="+vkey+"&uin=0&fromtag=91&.flac"
    url_m4a = "http://dl.stream.qqmusic.qq.com/C400"+songmid+".m4a?guid=552068528&vkey="+vkey+"&uin=0&fromtag=66"

    获取mp3和mpe

    get_temp_url = 'https://c.y.qq.com/base/fcgi-bin/fcg_music_express_mobile3.fcg?'
    temp_form = {
    "g_tk": "191874193",
    "loginUin": "1069486284",
    "hostUin": "0",
    "format": "json",
    "inCharset": "utf8",
    "outCharset": "utf-8",
    "notice": "0",
    "platform": "yqq",
    "needNewCode": "0",
    "cid": "205361747",
    "uin": "1069486284",
    "songmid": songmid,
    "filename": "M500" + songmid + ".mp3",
    "guid": "2057046240"
    }
    temp_link = requests.get(get_temp_url, params=temp_form, headers=random_header())
    temp_link = temp_link.json()
    temp_link = temp_link["data"]["items"][0]
    url_mp3 = "http://dl.stream.qqmusic.qq.com/" + temp_link["filename"] + "?guid=2057046240&vkey=" + temp_link[
    "vkey"] + "&uin=0&fromtag=88"
    print("1.flac:     "+url_flac)
    print("2.ape:      "+url_ape)
    print("3.mp3:      "+url_mp3)
    print("4.m4a:      "+url_m4a)

    choice={
    "1":url_flac,
    "2":url_ape,
    "3":url_mp3,
    "4":url_m4a
    }
    type={
    "1": ".flac",
    "2": ".ape",
    "3": ".mp3",
    "4": ".m4a"
    }
    n = int(input('请选择:'))

    print(choice[str(n)])
    try:
    urllib.request.urlretrieve(choice[str(n)],singName+"-"+singer_name+type[str(n)])
    print("下载完成")
    except:
    print("下载失败")

    展开全文
  • 今天小编就为大家分享一篇用Python爬取QQ音乐评论并制成词云图的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
  • 原博文2020-08-09 12:56 −1、爬取QQ音乐榜单数据并存入数据库(MySQL)2、代码import requestsimport jsonfrom bs4 import BeautifulSoupimport pymysql def get_html(): url='https:/...相关推荐2019-12-20 10:22 ...

    原博文

    2020-08-09 12:56 −

    1、爬取QQ音乐榜单数据并存入数据库(MySQL)

    2、代码

    import requests

    import json

    from bs4 import BeautifulSoup

    import pymysql def get_html(): url='https:/...

    相关推荐

    2019-12-20 10:22 −

    1.DllImport 是什么?

    DllImport是System.Runtime.InteropServices命名空间下的一个属性类,其功能是提供从非托管DLL(托管/非托管是微软的.net framework中特有的概念,其中,非托管代码也叫本地(native)代码。与Java中的机制类似,也...

    2019-12-20 13:35 −

    最新在学习Python的基础入门系列课程,今天学习到使用python 的内置库smtplib发送邮件内容。

    使用Python发送邮件步骤简单: 1. 创建SMTP连接 2. 使用邮箱和密码登录SMTP服务器 3. 创建邮件内容对象EmailMessage, 并使用set_content方法设置邮件...

    2019-12-25 10:10 −

    <?php

    /**

    * Project:QQ授权登陆

    * User: luokakale

    * Date: 2019/1/25

    * Time: 14:22

    */ //应用的APPID

    $app_id = "";

    //应用的APPKEY

    $app_secret = "";

    //【成功授权】后的回...

    comment.png

    0

    attention.png

    382

    2019-11-29 11:43 −

    # WireShark抓取QQ邮箱

    > 实验环境:MacOS + WireShark

    > ## 1.QQ邮箱是网址是基于HTTPS协议的

    HTTPS(Hypertext Transfer Protocol over Secure Socket Layer)能够加密信息,由HTTP+TLS/SSL组成...

    comment.png

    0

    attention.png

    1087

    2019-12-25 23:07 −

    Serializers 串列器 序列化器 串行器

    MemoryStream 创建其支持存储区为内存的流。

    BinaryFormatter 以二进制格式将对象或整个连接对象图形序列化和反序列化。

    System.Runtime.Serializ...

    2019-12-12 14:38 −

    1、准备第三方包:

    py -3.6 -m pip install win32gui

    py -3.6 -m pip install Pywin32

    py -3.6 -m pip...

    2019-12-25 20:58 −

    首先安装pillow

    pip install pillow

    然后安装keyboard

    pip install keyboard

    安装完毕,对ctrl+alt+a按键进行监听,由于不知道截图需要多久,所以截取完毕后需要按一下键盘c进行中断,之后利用ImageGrab模块进行截取的读取,然后将截...

    展开全文
  • python爬取qq音乐下载歌曲 完整代码: import requests import json from urllib.request import urlretrieve from selenium import webdriver import re import os def get_music_url(): driver.get(f'...
  • fromtag=0") #save_mp3(i[1],res,word) thr = threading.Thread(target=save_mp3, args=(i[1],res,word)) # 启动线程 thr.start() print("下载完成") print("done") send_request() 找到QQ音乐的搜索歌曲APIhttps://...
  • 序:python强大的功能,可以爬取网上的某些信息,本次主要是通过爬歌单信息熟悉下python基础。用到知识点:1、python3、urllib.request.openurl2、json (json字符串解析为python对象)3、python 文件操作,爬取到的...
  • Python爬取qq音乐的过程实例

    千次阅读 2019-01-11 16:16:10
    一、前言  qq music上的音乐还是不少的,有些时候想要...二、Python爬取QQ音乐单曲 爬虫步骤 1.确定目标 首先我们要明确目标,本次爬取的是QQ音乐歌手刘德华的单曲。 (百度百科)-&gt;分析目标(策略...
  • python爬取qq音乐歌曲

    千次阅读 2021-03-11 11:51:23
    1.找到我们要爬取的歌曲主页 ...:网页版的qq音乐它只展示几首音乐,全部音乐需要在客户端里面听。还有代码里面的2325794997是我的qq号 你们可以写自己的也可以写0 from lxml import etree import requests i
  • python爬取qq音乐免费歌曲 2020.7.26目标分析获取音乐列表1.浏览器网络请求追踪2.寻找音乐列表解析qq音乐下载连接组成获取vkey获取sign参数 目标分析 做一个音乐爬虫。 输入关键词,获取音乐列表与音乐下载连接 获取...
  • Python爬取QQ音乐内地专辑

    千次阅读 2018-01-04 18:25:24
    好久没写博客,中间玩了两天基于python的web开发,然继续学爬虫了,花三天做了一个小练习,爬取qq音乐所有的内地专辑内容 用到的工具:Chrome、Pycharm社区版、Anaconda Pycharm建立py文件后,引入anaconda的库,...
  • ** 小福利,用python爬取qq音乐歌单并保存为excel文件,话不多说,上代码 ** import requests, openpyxl wb = openpyxl.Workbook() sheet = wb.active sheet.title = 'geci' sheet['A1'] = '歌曲名' # 加表头,给...
  • QQ音乐评论爬取分析1.随便选个音乐2. g_tk函数介绍 1.随便选个音乐 https://y.qq.com/n/yqq/song/0039MnYb0qxYhV.html 找到评论的数据接口: ...g_tk=1728726093&loginUin=0&hostUin=0&...
  • #爬取qq音乐周杰伦首页歌词 import requests from bs4 import BeautifulSoup import json import re URL = 'https://c.y.qq.com/soso/fcgi-bin/client_search_cp?' headers = { 'origin':'https://y.qq.com', '...
  • import re pattern = re.compile(r'\[em\](.*?)\[/em\]') df['content'] = df.content.str.replace(pattern, '') df.head()

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,564
精华内容 625
关键字:

python爬取qq音乐

python 订阅