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

以某狗音乐为例

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



相关推荐
用户2519162427111 小时前
Python之语言特点
python
刘立军2 小时前
使用pyHugeGraph查询HugeGraph图数据
python·graphql
数据智能老司机5 小时前
精通 Python 设计模式——创建型设计模式
python·设计模式·架构
数据智能老司机6 小时前
精通 Python 设计模式——SOLID 原则
python·设计模式·架构
c8i7 小时前
django中的FBV 和 CBV
python·django
c8i8 小时前
python中的闭包和装饰器
python
这里有鱼汤11 小时前
小白必看:QMT里的miniQMT入门教程
后端·python
TF男孩21 小时前
ARQ:一款低成本的消息队列,实现每秒万级吞吐
后端·python·消息队列
该用户已不存在1 天前
Mojo vs Python vs Rust: 2025年搞AI,该学哪个?
后端·python·rust
站大爷IP1 天前
Java调用Python的5种实用方案:从简单到进阶的全场景解析
python