|  | 
 
| 
import pprint
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  import os
 import requests
 import parsel
 import re
 
 filename = 'music\\'
 if not os.path.exists(filename):
 os.mkdir(filename)
 
 url = 'https://www.kugou.com/yy/html/rank.html'
 
 headers = {'user-agen':'Mzilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36 Edg/92.0.902.55'}
 response = requests.get(url=url,headers=headers)
 # print(response.text)
 selector = parsel.Selector(response.text)
 href = selector.css('.pc_rank_sidebar li a::attr(href)').getall()
 for index in href:
 response_2 = requests.get(url=index, headers=headers)
 Hash_list = re.findall('"Hash":"(.*?)"', response_2.text)
 id_list = re.findall('"album_id":(\d+),',response_2.text)
 zip_data = zip (Hash_list,id_list)
 for link in zip_data:
 hash = link[0]
 music_id = link[1]
 link_url = 'https://wwwapi.kugou.com/yy/index.php   '
 params = {
 'r': 'play/getdata',
 'callback':'jQuery1910140801497177923_1627403425983',
 'hash':   hash,
 'dfid':  '2Avi6d04PHEY48DIMp0wRG4k',
 'mid':'fe9e2dfe307a2f0cfde7e6a474d2f98c',
 'platid': '4',
 'album_id': music_id,
 '_':    '1627403425984',
 }
 response_3 = requests.get(url=link_url,params=params,headers=headers)
 pprint.pprint(response_3.json())
 music_url = response_3.json()['data']['play_url']
 music_name = response_3.json()['data']['audio_name']
 
 music_content = requests.get(url=music_url,headers=headers).content
 with open('music\\'+'.mp3',mode='wb') as f:
 f.write(music_content)
 print('正在保存:',music_name)
 
 
 
 
 
复制代码href = selector.css('.pc_rank_sidebar li a::attr(href)').getall()
href = selector.css('.pc_rank_sidebar li a::attr(href)').getall()   # ::改成英文的。
 | 
 
这个是报错代码   |