# coding=utf-8
# !/usr/bin/env python
'''
author: dangxusheng
desc : 稍微有点难度,需要多次请求获取key
date : 2018-08-29
''' # 导入模块
import requests
from lxml import etree
import json
import time # 准备全局变量
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.63 Safari/537.36 Qiyu/2.1.1.1",
"Referer": "https://y.qq.com/portal/player.html"
} # 获取歌手列表
# https://y.qq.com/portal/singer_list.html
def get_singer_list():
url = "https://u.y.qq.com/cgi-bin/musicu.fcg?callback=getUCGI25738961582047115&g_tk=5381&jsonpCallback=getUCGI25738961582047115&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq&needNewCode=0&data=%7B%22comm%22%3A%7B%22ct%22%3A24%2C%22cv%22%3A10000%7D%2C%22singerList%22%3A%7B%22module%22%3A%22Music.SingerListServer%22%2C%22method%22%3A%22get_singer_list%22%2C%22param%22%3A%7B%22area%22%3A-100%2C%22sex%22%3A-100%2C%22genre%22%3A-100%2C%22index%22%3A-100%2C%22sin%22%3A0%2C%22cur_page%22%3A1%7D%7D%7D"
headers['Referer'] = "https://y.qq.com/portal/singer_list.html"
ie = requests.session()
rep = ie.get(url, headers=headers)
html = rep.content.decode('utf-8')[25:-1]
singer_list = json.loads(html)['singerList']['data']['singerlist']
ls = []
for singer in singer_list:
singer_mid = singer['singer_mid']
singer_name = singer['singer_name']
singer_pic = singer['singer_pic']
ls.append({'singer_mid': singer_mid, "singer_name": singer_name, "singer_pic": singer_pic})
return ls
# print(ls)
# exit() # 获取专辑列表
def get_album_list(singer_mid=''):
url = "https://u.y.qq.com/cgi-bin/musicu.fcg?callback=getUCGI2613146679247198&g_tk=5381&jsonpCallback=getUCGI2613146679247198&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq&needNewCode=0&data=%7B%22singerAlbum%22%3A%7B%22method%22%3A%22get_singer_album%22%2C%22param%22%3A%7B%22singermid%22%3A%22" + singer_mid + "%22%2C%22order%22%3A%22time%22%2C%22begin%22%3A0%2C%22num%22%3A5%2C%22exstatus%22%3A1%7D%2C%22module%22%3A%22music.web_singer_info_svr%22%7D%7D"
headers['Referer'] = "https://y.qq.com/n/yqq/singer/" + singer_mid + ".html"
ie = requests.session()
rep = ie.get(url, headers=headers)
html = rep.content.decode('utf-8')[24:-1]
ablum_list = json.loads(html)['singerAlbum']['data']['list']
ls = []
for item in ablum_list:
album_mid = item['album_mid']
album_name = item['album_name']
singer_mid = item['singer_mid']
singer_name = item['singer_name']
ls.append(
{'album_mid': album_mid, 'album_name': album_name, 'singer_mid': singer_mid, 'singer_name': singer_name})
return ls # 根据专辑ID下载
def download_music_by_albumid(albummid='', singername=''):
# albummid = "001mTkmb4GJlh4"
url = "https://c.y.qq.com/v8/fcg-bin/fcg_v8_album_info_cp.fcg?albummid=" + albummid + "&g_tk=5381&jsonpCallback=albuminfoCallback&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq&needNewCode=0"
headers['Referer'] = "https://y.qq.com/portal/player.html"
ie = requests.session()
rep = ie.get(url, headers=headers)
html = rep.content.decode('utf-8')[19:-1]
song_list = json.loads(html)['data']['list']
for song in song_list:
song_name = song['songname']
song_mid = song['songmid']
get_key_url = "https://u.y.qq.com/cgi-bin/musicu.fcg?callback=getplaysongvkey0996617262271613&g_tk=5381&jsonpCallback=getplaysongvkey0996617262271613&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq&needNewCode=0&data=%7B%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%228216405924%22%2C%22songmid%22%3A%5B%22" + song_mid + "%22%5D%2C%22songtype%22%3A%5B0%5D%2C%22uin%22%3A%220%22%2C%22loginflag%22%3A1%2C%22platform%22%3A%2220%22%7D%7D%2C%22comm%22%3A%7B%22uin%22%3A0%2C%22format%22%3A%22json%22%2C%22ct%22%3A20%2C%22cv%22%3A0%7D%7D"
rep = ie.get(get_key_url, headers=headers)
html = rep.content.decode('utf-8')[32:-1]
data = json.loads(html)['req_0']['data']
download_url_1 = data['sip'][0]
download_url_2 = data['midurlinfo'][0]['purl']
filename = data['midurlinfo'][0]['filename']
url = download_url_1 + download_url_2
rep = ie.get(url, headers=headers, stream=True)
with open('./qqmusic/%s' % (song_name + "-" + singername + "-" + filename), 'wb') as file:
for byte_data in rep.iter_content(1024):
file.write(byte_data)
print('《%s》 下载成功!' % song_name)
time.sleep(2) # 入口函数
if __name__ == '__main__':
# 先获取歌手列表
ls = get_singer_list()
for singer in ls:
# 获取歌手的专辑列表
album_list = get_album_list(singer['singer_mid'])
singer_name = singer['singer_name']
# 下载专辑的所有歌曲
for album in album_list:
download_music_by_albumid(album['album_mid'], singer_name)
time.sleep(2)
exit()

爬虫下载QQ音乐:获取所有歌手-每个歌手的专辑-每个专辑里的歌曲的更多相关文章

  1. Python 应用爬虫下载QQ音乐

    Python应用爬虫下载QQ音乐 目录: 1.简介怎样实现下载QQ音乐的过程: 2.代码 1.下载QQ音乐的过程 首先我们先来到QQ音乐的官网: https://y.qq.com/,在搜索栏上输入一首 ...

  2. go 下载qq音乐

    //go下载qq音乐 package main import ( _ "fmt" jsoniter "github.com/json-iterator/go" ...

  3. 亲测可用!免费下载QQ音乐大部分资源!

    优化后亲测可用!免费下载QQ音乐大部分资源 通知 时间问题 博客园这边暂时停更要下载的去GitHub或者90盘 GitHub项目地址 https://github.com/TotoWang-hhh/m ...

  4. JY播放器【QQ音乐破解下载】

    今天给大家带来一款神器----JY播放器.可以直接下载QQ音乐的歌曲. 目前已经支持平台(蜻蜓FM.喜马拉雅FM.网易云音乐.QQ音乐) 使用方法: 在网页打开QQ音乐网站找到你要听的歌曲或歌单.复制 ...

  5. 手把手教你使用Python抓取QQ音乐数据(第一弹)

    [一.项目目标] 获取 QQ 音乐指定歌手单曲排行指定页数的歌曲的歌名.专辑名.播放链接. 由浅入深,层层递进,非常适合刚入门的同学练手. [二.需要的库] 主要涉及的库有:requests.json ...

  6. Deepin-安装QQ音乐(Windows程序)

    打开命令行,输入: sudo apt-get install wine 安装完成后,下载QQ音乐的安装包 然后安装 示例:wine xx.exe 实例:wine QQMusic.exe 安装完成,启动 ...

  7. Python Scrapy的QQ音乐爬虫 音乐下载、爬取歌曲信息、歌词、精彩评论

    QQ音乐爬虫(with scrapy)/QQ Music Spider UPDATE 2019.12.23 已实现对QQ音乐文件的下载,出于版权考虑,不对此部分代码进行公开.此项目仅作为学习交流使用, ...

  8. Python爬虫实战一之爬取QQ音乐

    一.前言   前段时间尝试爬取了网易云音乐的歌曲,这次打算爬取QQ音乐的歌曲信息.网易云音乐歌曲列表是通过iframe展示的,可以借助Selenium获取到iframe的页面元素, 而QQ音乐采用的是 ...

  9. QQ音乐MP3下载

    QQ音乐MP3下载 没错本次写的内容的对象是我们熟知的QQ Music. 本篇文章涉及内容包括:Python,爬虫,json解析,request 库的使用 缘起 前几天刷B站无意中又刷到了一首神曲,“ ...

随机推荐

  1. Java学习之Java接口回调理解

    Java接口回调 在Java学习中有个比较重要的知识点,就是今天我们要讲的接口回调.接口回调的理解如果解释起来会比较抽象,我一般喜欢用一个或几个经典的例子来帮助加深理解. 举例:老板分派给员工做事,员 ...

  2. pandas 中的模糊匹配

  3. 梯有N阶,上楼可以一步上一阶,也可以一步上二阶。编写一个程序,计算共有多少中不同的走法?

    c语言实现,小伙伴们谁要有更好的实现方法,要告诉我呦 #include int main(void) { int f,i,f1=1,f2=2; printf("请输入楼梯数"); ...

  4. ReSharper反编译C#类库

    经常会在使用C#类中的某个函数时想了解其中具体的代码,可是F12转到定义后只能看到函数简单的声明, 看不到方法体中的代码,这挺让人沮丧的.. 如下: F12进入后显示的是元数据, Equals函数只能 ...

  5. org.apache.spark.rpc.RpcTimeout$$anonfun$1.applyOrElse

    跑sparkPis示例程序 [root@node01 bin]# ./spark-submit --master spark://node01:7077 --class org.apache.spar ...

  6. ansible的logging模块用来写日志

    [root@node-1 library]# cat dolog.py #!/bin/env python ANSIBLE_METADATA = { 'metadata_version': 'alph ...

  7. java 安装以及配置

    1.下载 JDK 下载地址:https://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html 2.环境变量配 ...

  8. spark actions 算子

    package action; import org.apache.spark.SparkConf; import org.apache.spark.api.java.JavaPairRDD; imp ...

  9. Centos6.5升级openssh、OpenSSL和wget

    1.OpenSSL 1.1.查看版本 使用如下命令查看版本: openssl version 1.2.安装gcc依赖 yum -y install gcc gcc-c++ 1.3.安装配置 ./con ...

  10. Vs2017 typescript 开发小问题

    最近想写点ts的东西,以前用vs2015很方便,直接创建一个ts app项目就折腾了. Vs2017打开,居然发现这个项目模板不见了.   于是研究了一下,由于原来的ts app项目就是一个asp.n ...