16.ajax_case09
import requests
import json
import re
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from multiprocessing import Pool
def download_music(songmid, music_name):
url = 'https://c.y.qq.com/base/fcgi-bin/fcg_music_express_mobile3.fcg?g_tk=872989112&jsonpCallback=MusicJsonCallback06459212607938936&loginUin=11297258&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq&needNewCode=0&cid=205361747&callback=MusicJsonCallback06459212607938936&uin=11297258&songmid={0}&filename=C100{0}.m4a&guid=9136027940'.format(
songmid)
html = requests.get(url)
# 去掉jsonp
music_json = json.loads(re.findall(r'^\w+\((.*)\)$', html.text)[0])
filename = music_json['data']['items'][0]['filename']
vkey = music_json['data']['items'][0]['vkey']
download_url = 'http://dl.stream.qqmusic.qq.com/{}?vkey={}&fromtag=66'.format(
filename, vkey)
print(download_url)
# 下载到本地
music = requests.get(download_url)
# 文件名去除特殊符号
with open("d:\\music\\{}.m4a".format(re.sub(r'[\s+|@<>:\\"/]', '', music_name)), "wb") as m:
m.write(music.content)
def view_html():
# qq音乐页面是js加载的,这里用chrome headless模式访问
option = webdriver.ChromeOptions()
option.add_argument('headless')
driver = webdriver.Chrome(
r'D:\Program Files\Python\chromedriver.exe',
chrome_options=option)
# 排行榜页面
driver.get('https://y.qq.com/n/yqq/toplist/26.html')
print(driver.title)
try:
# 等待播放列表加载完毕
WebDriverWait(
driver, 10).until(
EC.presence_of_element_located(
(By.CLASS_NAME, "songlist__songname_txt")))
lis = driver.find_elements_by_class_name('songlist__songname_txt')
pattern = re.compile(r'https://y.qq.com/n/yqq/song/(\S+).html')
for i in range(lis.__len__()):
li = lis.__getitem__(i)
a = li.find_element_by_class_name('js_song')
# 获得songid
href = a.get_attribute('href')
music_name = a.get_attribute('title')
m = pattern.match(href)
download_music(m.group(1), music_name)
finally:
driver.quit()
if __name__ == '__main__':
view_html()
16.ajax_case09的更多相关文章
- 在Ubuntu 16.10安装mysql workbench报未安装软件包 libpng12-0错误
1.安装mysql workbench,提示未安装软件包 libpng12-0 下载了MySQL Workbench 6.3.8 在安装的时候报错: -1ubu1604-amd64.deb 提示: ...
- Ubuntu 16.10 安装KolourPaint 4画图工具
KolourPaint 4画图工具简单实用,可以绘画.视频处理和图标编辑: • 绘画:绘制图表和“手绘” • 视频处理:编辑截图和照片;应用特效 • 图标编辑:绘画剪贴和标识透明化 1.在Ubuntu ...
- 真正的汉化-PowerDesigner 16.5 汉化
一.背景 经常使用PowerDesigner,之前使用15版本,后来16出来后,就一直在使用16,不过一直是英文.一些同事对使用英文版总显示有些吃力. 遍寻百度.必应,都没有找到真正的针对版本16的汉 ...
- Win7安装MySQL-5.7.16过程
1.在C盘新建MYSQL文件夹:2.将mysql-5.7.16-winx64拷贝到C:\MYSQL文件夹下,更名为mysql-5.7.16:3.在mysql-5.7.16目录下,建my.ini文件,内 ...
- 使用 GCC 和 GNU Binutils 编写能在 x86 实模式运行的 16 位代码
不可否认,这次的标题有点长.之所以把标题写得这么详细,主要是为了搜索引擎能够准确地把确实需要了解 GCC 生成 16 位实模式代码方法的朋友带到我的博客.先说一下背景,编写能在 x86 实模式下运行的 ...
- 企业IT管理员IE11升级指南【16】—— 使用Compat Inspector快速定位IE兼容性问题
企业IT管理员IE11升级指南 系列: [1]—— Internet Explorer 11增强保护模式 (EPM) 介绍 [2]—— Internet Explorer 11 对Adobe Flas ...
- ABP(现代ASP.NET样板开发框架)系列之16、ABP应用层——数据传输对象(DTOs)
点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之16.ABP应用层——数据传输对象(DTOs) ABP是“ASP.NET Boilerplate Project ...
- 安装MYSQL详细教程 版本:mysql-installer-community-5.7.16.0 免安装版本和安装版本出现错误的解决
一.版本的选择 之前安装的Mysql,现在才来总结,好像有点晚,后台换系统了,现在从新装上Mysql,感觉好多坑,我是来踩坑,大家看到坑就别跳了,这样可以省点安装时间,这个折腾了两天,安装了好多个版本 ...
- C#开发微信门户及应用(16)-微信企业号的配置和使用
在本系列随笔的前面,主要就是介绍微信公众号的门户应用开发,最近把整个微信框架进行了扩展补充,增加了最新的企业号的API封装和开发,后续主要介绍如何利用C#进行微信企业号的开发工作,本篇作为微信企业号的 ...
随机推荐
- 使用Git 上传文件到云端(版本库)
第一步:本地初始化Git版本库 git init 第二步:链接码云(云端) git remote add orgin "你的远程仓库地址"(复制链接后结尾是.git,如果没有记得加 ...
- 【JZOJ6419】模拟旅行&【BZOJ5506】【luoguP5304】旅行者
description 某国有n座城市,这些城市之间通过m条单向道路相连,已知每条道路的长度. 不过,小X只对其中k座城市感兴趣. 为了更好地规划模拟旅行路线,提升模拟旅行的体验,小X想要知道他感兴趣 ...
- mui与springMVC前后端分离
这个小dome简单来说的前后端分离,通过跨域调用接口来显示数据. 前端用到mui框架,主要来显示数据. 后端用到Java的springMVC,restful服务来做增删改查管理, 这里主要实现动态显示 ...
- C#利用栈实现字符串运算解析
附上参考文章链接:https://blog.csdn.net/qq_34831781/article/details/80104219 本人整合修复一些bug后的代码 using System; us ...
- PostgreSQL/GREENPLUM关联更新
update a_t AA set /*AA.*/ sqlstr = 'qqq' from a_t BB where aa.id <> BB.id and aa.name = BB.nam ...
- 微信-小程序-开发文档-服务端-模板消息:templateMessage.send
ylbtech-微信-小程序-开发文档-服务端-模板消息:templateMessage.send 1.返回顶部 1. templateMessage.send 本接口应在服务器端调用,详细说明参见服 ...
- RoadFlow2.7.5 MyController.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- LeetCode刷题笔记-BFS-二叉树层次遍历
题目描述: 给定一个二叉树,返回其节点值自底向上的层次遍历. (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历) 例如:给定二叉树 [3,9,20,null,null,15,7], 3 / \ ...
- mybatis浅显认识
mybatis主配置文件: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configu ...
- eclispe 创建maven 项目:Could not resolve archetype org.apache.maven.archetypes
昨天新装eclispe 后,创建maven工程后出现 Could not resolve archetype org.apache.maven.archetypes:maven-archetype-q ...