夜班机器人的博客

夜班机器人的博客

python获取酷狗音乐top500的下载地址 MP3格式

# -*- coding: utf-8 -*-
# @Time    : 2018/4/16
# @File    : kugou_top500.py
# @Software: PyCharm
# @pyVer   : python 2.7

import requests,json
headers={
        'UserAgent' : 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3',
        'Referer' : 'http://m.kugou.com/rank/info/8888',
        'Cookie' : 'UM_distinctid=161d629254c6fd-0b48b34076df63-6b1b1279-1fa400-161d629255b64c; kg_mid=cb9402e79b3c2b7d4fc13cbc85423190; Hm_lvt_aedee6983d4cfc62f509129360d6bb3d=1523818922; Hm_lpvt_aedee6983d4cfc62f509129360d6bb3d=1523819865; Hm_lvt_c0eb0e71efad9184bda4158ff5385e91=1523819798; Hm_lpvt_c0eb0e71efad9184bda4158ff5385e91=1523820047; musicwo17=kugou'
        }

def get_songs(url):
    res=requests.get(url,headers=headers)
    return res.text

def get_song_download_url(url):
    res=requests.get(url,headers=headers)
    res_tmp_list = json.loads(res.text)
    return res_tmp_list['data']['play_url']

def get_song_page_data(url):
    Song_Json = json.loads(get_songs(URL))
    Song_List_Json = Song_Json['data']['info']
    total = []
    for i in range(len(Song_List_Json)):
        song_download_url = "http://www.kugou.com/yy/index.php?r=play/getdata&hash=%s&album_id=%s&_=1523819864065" % (Song_List_Json[i]['hash'], Song_List_Json[i]['album_id'])
        song_data_dict = {'downloadUrl':get_song_download_url(song_download_url),'fileName':Song_List_Json[i]['filename']}
        total.append(song_data_dict)
    return total

for i in range(1,18):
    URL='http://mobilecdngz.kugou.com/api/v3/rank/song?rankid=8888&ranktype=2&page=%s&pagesize=30&volid=&plat=2&version=8955&area_code=1' % i
    page_list_data = get_song_page_data(URL)
    for j in range(len(page_list_data)):
        print "%s   %s" % (page_list_data[j]['fileName'],page_list_data[j]['downloadUrl'])

效果

阅读更多
个人分类: python
上一篇nmap的十条命令
下一篇多线程检测域名存活状态 python3
想对作者说点什么? 我来说一句

实战: 爬虫练习,酷狗TOP500

2018年05月13日 3KB 下载

没有更多推荐了,返回首页

关闭
关闭