admin 管理员组

文章数量: 887021

import json

import requests

# 伪装自己
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'}

# 音乐列表
list_url = 'https://complexsearch.kugou/v2/search/song?callback=callback123&srcappid=2919&clientver=1000&clienttime=1667288844594&mid=e7e1f8d8b618c3f97c2aba28b4f55b26&uuid=e7e1f8d8b618c3f97c2aba28b4f55b26&dfid=1JdK2h1LxMaA3uebLz1TBsjA&keyword=%E5%91%A8%E6%9D%B0%E4%BC%A6&page=1&pagesize=30&bitrate=0&isfuzzy=0&inputtype=0&platform=WebFilter&userid=0&iscorrection=1&privilege_filter=0&filter=10&token=&appid=1014&signature=e729fe24eb3bbd3963c159c425563779'
list_resp = requests.get(list_url, headers=headers)
# 数据抽取
song_list = json.loads(list_resp.text[12:-2])['data']['lists'] 
for i, s in enumerate(song_list):
    print(f'{i + 1}----{s.get("SongName")}----{s.get("FileHash")}')
num = input('请输入要下载第几首音乐:')

# 音乐信息的url地址
info_url = f'https://wwwapi.kugou/yy/index.php?r=play/getdata&callback=jQuery19105948252723123195_1667288452509&hash={song_list[int(num) - 1].get("FileHash")}&dfid=1JdK2h1LxMaA3uebLz1TBsjA&appid=1014&mid=e7e1f8d8b618c3f97c2aba28b4f55b26&platid=4&album_id=966846&album_audio_id=32100650&_=1667288452511'
#
headers2 = {
    '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',
'Cookie': 'kg_mid=e7e1f8d8b618c3f97c2aba28b4f55b26; kg_dfid=1JdK2h1LxMaA3uebLz1TBsjA; kg_dfid_collect=d41d8cd98f00b204e9800998ecf8427e; kg_mid_temp=e7e1f8d8b618c3f97c2aba28b4f55b26; Hm_lvt_aedee6983d4cfc62f509129360d6bb3d=1667285044,1667308636; Hm_lpvt_aedee6983d4cfc62f509129360d6bb3d=1667308636'
}
info_resp = requests.get(info_url,headers = headers2)
print(info_resp.json()['data']['play_url'])

#这里是自己在csdn上面找的办法但是没用
def getHTMLText(url):
    maxTryNum = 20
    for tries in range(maxTryNum):
        try:
            kv = {"user-agent": "Mizilla/5.0"}
            response = requests.get(url, headers=kv, timeout=60)
            return response.text
        except:
            if tries < (maxTryNum - 1):
                continue
            else:
                print("Has tried %d times to access url %s, all failed!" % (maxTryNum, url))
                break



本文标签: 报错 找了 方法 教程 call