资源简介
music.py
代码片段和文件信息
#!/usr/bin/env python
# encoding: utf-8
“““
@author: sergiojune
@contact: 2217532592@qq.com
@site:
@software: PyCharm
@file: music.py
@time: 2018/8/8 16:15
“““
import requests
import random math
from Crypto.Cipher import AES
import base64
import codecs
import os
“““
获取歌曲地址:https://music.163.com/weapi/song/enhance/player/url?csrf_token=429d8812f4449bb9acb60e7647113999
“““
class Spider(object):
def __init__(self):
self.headers = {
# ‘User-Agent‘: ‘Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0‘
‘Cookie‘:‘_iuqxldmzr_=32; _ntes_nnid=8d4ef0883a3bcc9d3a2889b0bf36766a1533782432391; _ntes_nuid=8d4ef0883a3bcc9d3a2889b0bf36766a; __utmc=94650624; WM_TID=GzmBlbRkRGQXeQiYuDVCfoEatU6VSsKC; playerid=19729878; __utma=94650624.1180067615.1533782433.1533816989.1533822858.9; __utmz=94650624.1533822858.9.7.utmcsr=cn.bing.com|utmccn=(referral)|utmcmd=referral|utmcct=/; WM_NI=S5gViyNVs14K%2BZoVerGK69gLlmtnH5NqzyHcCUY%2BiWm2ZaHATeI1gfsEnK%2BQ1jyP%2FROzbzDV0AyJHR4YQfBetXSRipyrYCFn%2BNdA%2FA8Mv80riS3cuMVJi%2BAFgCpXTiHBNHE%3D; WM_NIKE=9ca17ae2e6ffcda170e2e6ee84b674afedfbd3cd7d98b8e1d0f554f888a4abc76990b184badc4f89e7af8ece2af0fea7c3b92a91eba9b7ec738e8abdd2b741e986a1b7e87a8595fadae648b0b3bc8fcb3f8eafb69acb69818b97ccec5dafee9682cb4b98bb87d2e66eb19ba2acaa5bf3b6b7b1ae5a8da6ae9bc75ef49fb7abcb5af8879f87c16fb8889db3ec7cbbae97a4c566e992aca2ae4bfc93bad9b37aab8dfd84f8479696a7ccc44ea59dc0b9d7638c9e82a9c837e2a3; JSESSIONID-WYYY=sHwCKYJYxz6ODfURChA471BMF%5CSVf3%5CTc8Qcy9h9Whj6CfMxw4YWTMV7CIx5g6rqW8OBv04YGHwwq%2B%5CD1N61qknTP%2Fym%2BHJZ1ylSH1EabbQASc9ywIT8YvOr%2FpMgvmm1cbr2%2Bd6ssMYXuTlpOIrKqp%5C%2FM611EhmfAfU47%5CSQWAs%2BYzgY%3A1533828139236‘
}
def __get_songs(self name):
d = ‘{“hlpretag“:“““hlposttag“:“““s“:“%s““type“:“1““offset“:“0““total“:“true““limit“:“30““csrf_token“:““}‘ % name
wyy = WangYiYun(d) # 要搜索的歌曲名在这里
data = wyy.get_data()
url = ‘https://music.163.com/weapi/cloudsearch/get/web?csrf_token=‘
response = requests.post(url data=data headers=self.headers).json()
return response[‘result‘]
def __get_mp3(self id):
d = ‘{“ids“:“[%s]““br“:320000“csrf_token“:““}‘ % id
wyy = WangYiYun(d)
data = wyy.get_data()
url = ‘https://music.163.com/weapi/song/enhance/player/url?csrf_token=‘
response = requests.post(url data=data headers=self.headers).json()
print(response)
return response[‘data‘][0][‘url‘]
def __download_mp3(self url filename):
“““下载mp3“““
abspath = os.path.abspath(‘.‘) # 获取绝对路径
os.chdir(abspath)
response = requests.get(url headers=self.headers).content
path = os.path.join(abspath filename)
with open(filename + ‘.mp3‘ ‘wb‘) as f:
f.write(response)
print(‘下载完毕可以在%s 路径下查看‘ % path + ‘.mp3‘)
- 上一篇:python音乐源代码
- 下一篇:老唐的1——python数据分析与机器学习实战
相关资源
- CpuMemSets在Linux操作系统中的实现
- Python学习全系列教程永久可用
- 蓝奏云批量上传工具.zip
- python书籍 PDF
- 老男孩python项目实战
- Python.rar99111
- decision_tree_v2.py
- Python绝技运用Python成为顶级黑客.pdf
- python小波包文档及论文.zip
- Python黑帽子(黑客与渗透测试编程之
- FlaskWeb开发:基于Python的Web应用开发实
- Python基础教程第3版中英文源码.rar
- python数据结构与算法中文版.zip
- Python-冲顶大会芝士超人西瓜视频头脑
- time_series_forecasting_with_python.zip
- Python基础教程第三版PDF高清可复制.
- python编程从入门到实践.zip237878
- FlaskWeb开发:Python基于Web应用开发实战
- pythonBCRMDSJ.mobi
- 量化交易之路用Python做股票量化分析
- PYTHON自然语言处理中文版.pdf
- Python基础教程(第3版).rar
- GRAYHATPYTHON高清.英文.书签版.pdf
- Python简明教程第四版.rar
- Python编程:从入门到实践带书签完整
- Python基础教程(第3版).pdf109608
- vamei-从Python开始学编程.pdf
- 利用Python进行数据分析.pdf
- 小甲鱼零基础学python课后习题和答案
- Python编程:从入门到实践-PythonCrashC
评论
共有 条评论