• Python Requests批量下载音频


    Python Requests批量下载音频

    抓包: 下载抓包软件Charles https://www.charlesproxy.com/download/
    配置: https://blog.csdn.net/HeyShHeyou/article/details/90045204
    抓包手机应用: 手机和电脑在同一网络下,设置手机wifi代理,主机和端口

    Requests设置请求头Headers: https://blog.csdn.net/ysblogs/article/details/88530124

    requests 请求头_requests快速构造请求头的方法:
    https://blog.csdn.net/weixin_39905695/article/details/110770593

    python: requests:发送http请求 urllib.request:根据url和名字下载图片到指定路径 json:把str转成json格式 os:根据名字创建文件夹

    1,抓包查看所有音频类型,,id,name

    #构造简单请求头
    headers = {
        # "Host": "api.psy-1.com",
        # "Connection": "keep-alive",
        "packageid": "12",
        # "user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF XWEB/6500",
        # "Content-Type": "application/json",
        # "channelid": "2",
        # "referer": "https://servicewechat.com/wxf9e01cdca4779ccb/85/page-frame.html",
        # "xweb_xhr": "1",
        "platformid": "3",
        # "token": "374d74285154922b7f1f1150d985102d",
        "version": "7",
        # "Accept": "*/*",
        # "Sec-Fetch-Site": "cross-site",
        # "Sec-Fetch-Mode": "cors",
        # "Sec-Fetch-Dest": "empty",
        # "Accept-Encoding": "gzip, deflate, br",
        # "Accept-Language": "zh-CN,zh"
    }
    #请求路径
    urltest = 'https://api.psy-1.com/miniapp/v1/music/tag'
    #发送http请求
    response = requests.get(url=url,headers=headers,verify=False)
    #获取响应数据
    html = re.text
    #str转json
    j = json.loads(html)
    #获取data数据
    data = j["data"]
    typeDict = dict()
    #把数据存入字典方便使用
    for item in data:
        name = item['tag_name']
        id = item["tag_id"]
        typeDict[id] = name
    return typeDict
    2,抓包查看单个类别的信息 ![[@B@ELFO5~})A2_MNG)(87K3.png]]
    
    url = 'https://app/v1/tag/music
    response = requests.get(url=url,headers=headers,verify=False)
    html = response.text
    j = json.loads(html)#str转json
    data = j["data"]#获取data数据
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44

    根据上面抓包音频类型获得的类别名字创建文件夹用来存放不同类型的音频

    os.mkdir(r"D:\zsh\video\audio\%s"%typrName)
    #循环取出所有数据
    for item in data:
    	audioName = item["musicdesc"]#获取视频的name
        audioUrl = item["musicurl"]#获取到宝宝里6个视频的url
        # with open('audio.txt','a',encoding='utf-8') as f:
    	#     f.write(audioUrl+'\n')
    	#取一个下载一个音频
    	request.urlretrieve(audioUrl,r"D:\zsh\video\audio\%s\%s.mp3"%(typrName,audioName))#下载音频
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
  • 相关阅读:
    UWA Pipeline 2.3.2版本更新说明
    Pytorch CIFAR10图像分类 工具函数utils更新v2.0篇
    使用pycharm远程连接到Linux服务器进行开发
    MES管理系统与ERP系统的实施顺序与决策
    vue组件通信6种方式总结(常问知识点)
    【微信小程序授权】获取用户手机号,昵称
    C++程序调试详解(包括打断点 单步调试 数据断点...)
    L2-029 特立独行的幸福
    Android平台GB28181执法记录仪技术方案
    keepalived+nginx高可用集群
  • 原文地址:https://blog.csdn.net/qq_45437316/article/details/134465264