python 爬虫 30行爬虫代码教你爬取酷我音乐

写在前面:本作品不可用于任何商业途径,仅供学习交流
运行效果

python 爬虫 30行爬虫代码教你爬取酷我音乐_第1张图片

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/12/11 17:55
# @Author  : huni
# @File    : 酷我音乐.py
# @Software: PyCharm
import requests
if __name__ == '__main__':
    headers = {
     
        "Cookie": "_ga=GA1.2.1083049585.1590317697; _gid=GA1.2.2053211683.1598526974; _gat=1; Hm_lvt_cdb524f42f0ce19b169a8071123a4797=1597491567,1598094297,1598096480,1598526974; Hm_lpvt_cdb524f42f0ce19b169a8071123a4797=1598526974; kw_token=DX28GJM6EWU",
        'csrf': 'DX28GJM6EWU',
        'Referer': 'https://www.kuwo.cn/search/list?',
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36 Edg/84.0.522.63",
    }
    data = {
     
        'key': '燕无歇',  # 可换成其他要找的歌曲
        'pn': '1',
        'rn': '60',     # 可修改显示搜索结果的数量
        'httpsStatus': '1',
        'reqId': 'cfca58d0-3b96-11eb-8dc4-0b01b70e8f92'
    }
    url = 'https://www.kuwo.cn/api/www/search/searchMusicBykeyWord?'
    resp = requests.get(url=url,headers=headers,params=data).json()
    for i in resp['data']['list']:
        album = i['album']
        artist = i['artist']
        name = i['name']
        rid = i['rid']
        mp3url = f'https://www.kuwo.cn/url?format=mp3&rid={rid}&response=url&type=convert_url3&br=128kmp3'
        resp1 = requests.get(url=mp3url,headers=headers).json()
        print('专辑',album)
        print('歌手',artist)
        print('歌名',name)
        print('下载链接',resp1['url'])
        print('\n')






你可能感兴趣的:(爬虫,python,数据挖掘,机器学习,json,人工智能)