喜马拉雅单个无版权下载

import requests,re,json,os
from urllib import request

# 构建代理
proxy = {
    'http' : 'http://alice:[email protected]:6666',
    'https' : 'http://alice:[email protected]:6666'
}

headers={
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.4620.400 QQBrowser/9.7.13014.400",
}
Num=1    #最多21页
# for Num in range(1,22):
# 首页可以点击播放 ajax类型 选择ajax的url
url = 'https://www.ximalaya.com/revision/play/album?albumId=4164479&pageNum={}&sort=-1&pageSize=30'.format(Num)


# 发起get请求
response = requests.get(url,headers=headers,proxies=proxy)
# 获取json格式数据
html_dict=response.json()
# print(html_dict)
# print(type(html_dict))
# 返回字典类型  拿键取列表
url_list = html_dict['data']['tracksAudioPlay']
# 循环列表 拿取下载地址 
for url_str in url_list:
    trackName =url_str['trackName']
    url_m4a=url_str['src']
    if not os.path.exists('一说春秋/'):
        os.mkdir('一说春秋/')
     # 下载的路径与文件名字
    filename = '一说春秋/' + trackName + '.m4a'
    # 下载文件
    request.urlretrieve(url_m4a, filename)

猜你喜欢

转载自blog.csdn.net/q810935819/article/details/81779038