| |
| |
| |
| |
| import json |
| import os |
| from time import sleep |
| |
| import requests |
| from lxml import etree |
| |
| headers = { |
| 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.52' |
| } |
| |
| for n in range(23): |
| |
| home_url = f'https://www.kugou.com/yy/rank/home/{n + 1}-8888.html?from=homepage' |
| |
| home_res = requests.get(url=home_url, headers=headers).text |
| |
| e = etree.HTML(home_res) |
| |
| ms_url = e.xpath('//script[@type="text/javascript"]/text()') |
| |
| |
| for list in ms_url: |
| |
| list = list.strip() |
| |
| |
| list = list[list.index('[{'):list.rindex(';')].replace('-', '\\u002d').encode('utf-8') |
| |
| |
| list = list.decode("unicode_escape") |
| |
| |
| hash = json.loads(list) |
| |
| |
| for i in range(len(hash)): |
| h = hash[i] |
| |
| m_h = h.get('Hash') |
| m_id = h.get('album_id') |
| name = h.get('FileName') |
| |
| |
| music_url = f'https://wwwapi.kugou.com/yy/index.php?r=play/getdata&hash={m_h}' \ |
| f'&mid=e496ef938c1254f6efccb2e7cbccd1fb&album_id={m_id}' |
| |
| music_res = requests.get(music_url, headers).text |
| music_res = json.loads(music_res) |
| |
| ms_url = music_res['data'].get('play_url') |
| |
| ms_res = requests.get(ms_url, headers) |
| i = i + 1 |
| count = (len(hash) * n) + i |
| |
| if count < 10: |
| count = '00' + str(count) |
| elif 10 <= count < 100: |
| count = '0' + str(count) |
| else: |
| count = count |
| if not os.path.exists('./musicTop500'): |
| os.makedirs('./musicTop500') |
| with open(f'./musicTop500/{count}-{name}.mp3', 'wb') as f: |
| f.write(ms_res.content) |
| print(f'{name}下载完成!!!') |
| |
| sleep(2) |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)