【爬虫】单首音乐的爬取(附源码)

以某狗音乐为例

python 复制代码
import requests
import re
import time
import hashlib

def GetResponse(url):

    # 模拟浏览器
    headers ={
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0'
    }
    # 发送请求
    response = requests.get(url=url,headers=headers)
    # 返回内容
    return response

def GetInfo():
    # 请求网址
    link='https://wwwapi.kugou.com/play/songinfo?srcappid=2919&clientver=20000&clienttime=1709645100257&mid=99fdc9044912dc3185ee58da1a9f87d0&uuid=99fdc9044912dc3185ee58da1a9f87d0&dfid=3exBpJ2WlTHO4N287r0necyx&appid=1014&platid=4&encode_album_audio_id=9oevti38&token=2544e791bc15f255e8737748178f76680a2205d03c2259e2fc4892e9aa500045&userid=2195647882&signature=a6efee3c478d7a625553ab35eb149df9'
    JsonData = GetResponse(url=link).json()
    # 提取歌曲链接
    play_url = JsonData['data']['play_url']
    # 提取歌名
    audio_name = JsonData['data']['audio_name']
    # 获取数据
    return audio_name,play_url


def Save(title,url):
    # 对歌曲链接发送请求
    music_data = GetResponse(url=url).content
    # wb 保存模式
    with open("D:/music/{}.mp3".format(title), mode='wb') as f:
        f.write(music_data)


if __name__ == '__main__':
    audio_name,play_url = GetInfo()
    Save(audio_name,play_url)
    print(audio_name,'保存成功!!')

修改User-Agent,link,保存地址即可。



相关推荐
电商API&Tina几秒前
电商数据采集API接口||合规优先、稳定高效、数据精准
java·javascript·数据库·python·json
玲娜贝儿--努力学习买大鸡腿版13 分钟前
hot 100 刷题记录(1)
数据结构·python·算法
兮℡檬,31 分钟前
答题卡识别判卷
开发语言·python·计算机视觉
阆遤40 分钟前
利用TRAE对nanobot进行安全分析并优化
python·安全·ai·trae·nanobot
雕刻刀1 小时前
ERROR: Failed to build ‘natten‘ when getting requirements to build wheel
开发语言·python
何双新1 小时前
Odoo 技术演进全解析:从 Widget 到 Owl,从 Old API 到声明式 ORM
python
进击的雷神1 小时前
突破POST分页与IP封锁:基于表单提交和代理转发的新闻爬虫设计
爬虫·网络协议·tcp/ip
山川行2 小时前
关于《项目C语言》专栏的总结
c语言·开发语言·数据结构·vscode·python·算法·visual studio code
星辰徐哥2 小时前
C语言游戏开发:Pygame、SDL、OpenGL深度解析
c语言·python·pygame
xcLeigh2 小时前
Python入门:Python3基础练习题详解,从入门到熟练的 25 个实例(六)
开发语言·python·教程·python3·练习题