[Python] 纯文本查看 复制代码 import requests, os, re, time
for page in range(1,20):
url = f'http://www.htqyy.com/genre/musicList/1?pageIndex={page}&pageSize=20&order=hot'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36',
'Cookie': '__yjs_duid=1_0c41cb14b0ffd740aaddd4076f59580e1634292989442; blk=0; Hm_lvt_74e11efe27096f6ef1745cd53f168168=1634292990; isPlay=1; jploop=false; jpvolume=0.380; cm=11%20false; Hm_lpvt_74e11efe27096f6ef1745cd53f168168=1634293931',
'Referer': 'http://www.htqyy.com/home/music'
}
res = requests.get(url=url, headers=headers).content.decode()
music_info = re.findall('<span class="title"><a href="(.*?)" target="play" title=".*?" sid="(.*?)">(.*?)</a>', res)
for music_url, music_id, music_name in music_info:
music_urlpj = f'http://www.htqyy.com{music_url}'
ress = requests.get(music_urlpj).content.decode()
author_name = re.findall('">艺.*?术.*?家:<\/span><a href=".*?" title="(.*?)" ',ress)[0]
mp3_url = f'http://f3.htqyy.com/play9/{music_id}/mp3/5'
print(mp3_url)
down_mp3 = requests.get(url=mp3_url,headers=headers).content
if not os.path.exists('好听轻音乐网'):
os.mkdir('好听轻音乐网')
time.sleep(3)
with open(f'好听轻音乐网/{music_name}-{author_name}.mp3','wb') as f:
f.write(down_mp3)
print(f'当前正在下载:{music_name}')
|