爬虫实现批量下载酷狗音乐(旧)

2022-07-13 540 0

酷狗音乐有些歌曲需要VIP才能下载,通过python爬虫技术可以快速批量下载,由于酷狗现在已经改版,方法不可用,先学习里面的技术,以后再更新新版

下面放出代码

import requests
import re

url='https://www.kugou.com/yy/html/rank.html'
html=requests.get(url)
re_hash = re.compile('"Hash":"(.*?)"',re.S | re.I)
re_album_id = re.compile('"album_id":(\d+)',re.S | re.I)
re_song_url=re.compile('"play_url":"(,*?)"',re.S | re.I)
re_song_name=re.compile('"song_name":"(,*?)"',re.S | re.I)
hashs = re_hash.findall(html.text)
album_ids = re_album_id.findall(html.text)

for hash_,album_id in zip(hashs,album_ids):
#这个url是Network里面找到对应字典的headers---request URL
    detail_url = 'https://wwwapi.kugou.com/yy/index.php'
#下面的参数也是上述网页里面的
    params = {
        'r': 'play/getdata',
        'callback': 'jQuery191005764479255441324_1657352883715',
        'hash': '749C1612232D115402FCB186C6F92F00',
        'dfid': '08xbKl1Wfiao0dPcut4edEt5',
        'appid': '1014',
        'mid': '7844089f864287e5ed3cf327c285e03d',
        'platid': '4',
        'album_id': '58879774',
        'album_audio_id': '424968309',
        '_': '1657352883717'
    }

    song_html = requests.get(detail_url,params=params)
#到这一步就可以打印出歌曲的名称和歌曲的下载地址了。但是酷狗的名称都是先转换unicode转换
    song_url = re_song_url.findall(song_html.text)[0].replace('\\','')
    song_name = re_song_name.findall(song_html.text)[0]
    song_name = song_name.encode('utf-8').decode('unicode_escape')
    print(song_name,song_url)

相关文章

Tkinter学习(2)
Tkinter学习(1)
selenium自动化模块学习(5)
selenium自动化模块学习(4)
selenium自动化模块学习(3)
selenium自动化模块学习(2)

发布评论