1 import requests
import re
import json
import os # 便于存放作者的姓名
zuozhe = [] headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36'} def get_singermid():
name = input('请输入你要下载歌曲的作者:')
zuozhe.append(name)
if not os.path.exists(name):
os.mkdir(name)
url = 'https://c.y.qq.com/soso/fcgi-bin/client_search_cp'
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36'}
data = {
'w': name,
'jsonpCallback': 'MusicJsonCallback885332333726736',}
response = requests.get(url,headers=headers,params=data).text
patt = re.compile('MusicJsonCallback\d+\((.*?)\}\)')
singermid = re.findall(patt,response)[0]
singermid = singermid+'}'
dic = json.loads(singermid)
return dic['data']['song']['list'][0]['singer'][0]['mid'] def get_page_html(singermid):
url = 'https://c.y.qq.com/v8/fcg-bin/fcg_v8_singer_track_cp.fcg'
params = {
'g_tk': 5381,
'jsonpCallback': 'MusicJsonCallbacksinger_track',
'loginUin': 0,
'hostUin': 0,
'format': 'jsonp',
'inCharset': 'utf8',
'outCharset': 'utf-8',
'notice': 0,
'platform': 'yqq',
'needNewCode': 0,
'singermid': singermid,
'order': 'listen',
'begin': 0,# 页数 0 30 60
'num': 30,
'songstatus': 1,
}
response = requests.get(url,headers=headers,params=params)
return response.text def get_vkey_data(songmid,strMediaMid,name):
url = 'https://c.y.qq.com/base/fcgi-bin/fcg_music_express_mobile3.fcg'
strMediaMid1 = 'C400'+strMediaMid+'.m4a'
data = {
'g_tk': 5381,
'jsonpCallback': "MusicJsonCallback4327043425715609",
'loginUin': 0,
'hostUin': 0,
'format': 'json',
'inCharset': 'utf8',
'outCharset': 'utf-8',
'notice': 0,
'platform': 'yqq',
'needNewCode': 0,
'cid': 205361747,
'callback': 'MusicJsonCallback4327043425715609',
'uin': 0,
'songmid': songmid,
'filename': strMediaMid1,
'guid': 4428680404,
}
response = requests.get(url,headers=headers,params=data).text
try:
patt = re.compile('\"vkey\":\"(.*?)\"')
vkey = re.findall(patt,response)[0]
patt = re.compile('\"filename\":\"(.*?)\"')
filename = re.findall(patt, response)[0]
url1 = 'http://dl.stream.qqmusic.qq.com/' + filename + '?vkey=' + vkey + '&guid=4428680404&uin=0&fromtag=66'
yingyue = requests.get(url1,headers=headers).content
with open(zuozhe[0]+'/'+name+'.m4a','wb') as f:
f.write(yingyue)
f.close()
print('下载完成《'+name+'》')
except Exception as e:
print(e)
pass def get_detail_html(html):
if html:
patt = re.compile('data\":{\"list\":(.*?),\"singer_id',re.S)
json_html = re.findall(patt,html)[0]
data_html = json.loads(json_html)
for data in data_html:
name = data['musicData']['songname']
songmid = data['musicData']['songmid']
strMediaMid = data['musicData']['strMediaMid']
print('正在下载《' + name + '》......')
get_vkey_data(songmid,strMediaMid,name) def main():
# 获取 singermid
singermid = get_singermid()
html = get_page_html(singermid)
get_detail_html(html) if __name__ == '__main__':
main()

爬取qq音乐首先得找到'http://dl.stream.qqmusic.qq.com/' + filename + '?vkey=' + vkey + '&guid=4428680404&uin=0&fromtag=66'这个链接    然后其中只有filename 和vkey 在变化  然后就在列表页寻找这两个参数,找到以后拼接到这个url,然后请求就可以了 。

代码在上面只供参考

python3 可以直接复制然后运行

python3 爬取qq音乐作者所有单曲 并且下载歌曲的更多相关文章

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

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

  2. 爬取QQ音乐歌手的歌单

    import requests# 引用requests库res_music = requests.get('https://c.y.qq.com/soso/fcgi-bin/client_search ...

  3. 爬取QQ音乐(讲解爬虫思路)

    一.问题描述: 本次爬取的对象是QQmusic,为自己后面做django音乐网站的开发获取一些资源. 二.问题分析: 由于QQmusic和网易音乐的方式差不多,都是讲歌曲信息放入到播放界面播放,在其他 ...

  4. python3爬取咪咕音乐榜信息(附源代码)

    参照上一篇爬虫小猪短租的思路https://www.cnblogs.com/aby321/p/9946831.html,继续熟悉基础爬虫方法,本次爬取的是咪咕音乐的排名 咪咕音乐榜首页http://m ...

  5. 爬取qq音乐巅峰榜---内地音乐的榜单

    import requestsimport jsonimport sys for i in range(0,10): url = "https://szc.y.qq.com/v8/fcg-b ...

  6. python3 爬去QQ音乐

    import requests import re import json import os def get_name(singer): url = 'https://c.y.qq.com/soso ...

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

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

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

    [一.项目目标] 通过Python爬取QQ音乐数据(一)我们实现了获取 QQ 音乐指定歌手单曲排行指定页数的歌曲的歌名.专辑名.播放链接. 此次我们在之前的基础上获取QQ音乐指定歌曲的歌词及前15个精 ...

  9. python3爬取全民K歌

    Python3爬取全民k歌 环境 python3.5 + requests 1.通过歌曲主页链接爬取 首先打开歌曲主页,打开开发者工具(F12). 选择Network,点击播放,会发现有一个请求返回的 ...

随机推荐

  1. 【一天一道LeetCode】#45. Jump Game II

    一天一道LeetCode系列 (一)题目 Given an array of non-negative integers, you are initially positioned at the fi ...

  2. visual svn使用教程

     SVN简介: 为什么要使用SVN? 程序员在编写程序的过程中,每个程序员都会生成很多不同的版本,这就需要程序员有效的管理代码,在需要的时候可以迅速,准确取出相应的版本. Subversion是什 ...

  3. Eclipse搭建Android环境失败的解决方案

    今天在Eclipse上搭建Android开发环境,不仅在安装ADT的过程中老是出错,而且Android SDK下载后,打开SDK Manager时也无法链接到网页下载tools,网上查了好多方法,试了 ...

  4. OpenCV 使用光流法检测物体运动

    OpenCV 可以使用光流法检测物体运动,贴上代码以及效果. // opticalflow.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" ...

  5. HTTP2概述

    HTTP/2 提供了HTTP语义的传输优化.HTTP/2支持所有HTTP/1.1的核心特征,并且在其他方面做的更高效. HTTP/2中基本的协议单位是帧.每个帧都有不同的类型和用途.例如,报头(HEA ...

  6. Graph Cut and Its Application in Computer Vision

    Graph Cut and Its Application in Computer Vision 原文出处: http://lincccc.blogspot.tw/2011/04/graph-cut- ...

  7. 关于Android的https通讯安全

    原文链接:http://pingguohe.net/2016/02/26/Android-App-secure-ssl.html 起因 前段时间,同事拿着一个代码安全扫描出来的 bug 过来咨询,我一 ...

  8. Linux常用命令(第二版) --压缩解压缩命令

    压缩解压缩命令: ----------.gz---------- 1.压缩 gzip[GNU zip]: /bin/gzip 格式: gzip 选项 [文件] #压缩文件,压缩后扩展名为.gz,Lin ...

  9. LeetCode之“动态规划”:Dungeon Game

    题目链接 题目要求: The demons had captured the princess (P) and imprisoned her in the bottom-right corner of ...

  10. dex分包方案

    当一个app的功能越来越复杂,代码量越来越多,也许有一天便会突然遇到下列现象: 1. 生成的apk在2.3以前的机器无法安装,提示INSTALL_FAILED_DEXOPT 2. 方法数量过多,编译时 ...