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

以某狗音乐为例

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,保存地址即可。



相关推荐
知行合一。。。3 小时前
Python--04--数据容器(总结)
开发语言·python
架构师老Y3 小时前
008、容器化部署:Docker与Python应用打包
python·容器·架构
lifewange4 小时前
pytest-类中测试方法、多文件批量执行
开发语言·python·pytest
pluvium274 小时前
记对 xonsh shell 的使用, 脚本编写, 迁移及调优
linux·python·shell·xonsh
2401_827499994 小时前
python项目实战09-AI智能伴侣(ai_partner_5-6)
开发语言·python
PD我是你的真爱粉4 小时前
MCP 协议详解:从架构、工作流到 Python 技术栈落地
开发语言·python·架构
ZhengEnCi4 小时前
P2G-Python字符串方法完全指南-split、join、strip、replace的Python编程利器
python
是小蟹呀^4 小时前
【总结】LangChain中工具的使用
python·langchain·agent·tool
宝贝儿好5 小时前
【LLM】第二章:文本表示:词袋模型、小案例:基于文本的推荐系统(酒店推荐)
人工智能·python·深度学习·神经网络·自然语言处理·机器人·语音识别
王夏奇5 小时前
pythonUI界面弹窗设置的几种办法
python·ui