• python抓取网页视频


    1. 喜马拉雅音频

    1-1 喜马拉雅
    import requests
    import json
    import time
    import random
    import hashlib
    
    url = 'https://www.ximalaya.com/revision/play/v1/audio?id=46103875&ptype=1'
    
    headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.47'
    }
    
    #服务器时间戳
    severtime = requests.get('https://www.ximalaya.com/revision/time',headers=headers).text
    #现在时间戳
    nowtime = str(round(time.time()*1000)) #round()返回保留几位小数的值,默认为整数 //time.time()返回当前时间的时间戳//time.time()得10位数,目前时间戳为13位数
    
    #求加密的参数
    xm_sign = str(hashlib.md5('himalaya-{}'.format(severtime).encode()).hexdigest()) + '({})'.format(round(random.random()*100)) + severtime + '({})'.format(round(random.random()*100)) + nowtime
    #print(xm_sign)
    
    #更新请求头参数
    headers['xm-sign'] = xm_sign
    
    #提取及解析音频网址
    resp = requests.get(url,headers=headers)
    src_dic = json.loads(resp.text)
    src = src_dic['data']['src']
    
    #下载音频
    with open(f'./video/卖吊票-1.m4a',mode='wb') as f:
        f.write(requests.get(src,headers=headers).content)
    ##  再用格式工厂 转mp3 
    
    
    • 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

    在这里插入图片描述

    1-2 喜马拉雅
    import re
    import requests
    import re
    import requests
    import json
    import time
    import random
    import hashlib
    
    # 免费
    url = 'https://www.ximalaya.com/revision/play/v1/audio?id=46103875&ptype=1'
    
    # 收费的还不行 
    # url = 'https://audiofreepay.ali.xmcdn.com/download/1.0.0/storages/8987-audiopay/37/8B/GKwRIMAH8cjnANYGeAIF8P8Z-aacv2-48K_preview_1231196.m4a'
    # url = 'https://www.ximalaya.com/revision/play/v1/audio?id=620471242&ptype=1'
    
    headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'}
    
    # json_url = 'https://www.ximalaya.com/revision/play/v1/audio?id={}&ptype=1'.format(m4a_id)
    json_data = requests.get(url, headers=headers).json()# 
    print(json_data)# 提取音频地址
    m4a_url = json_data['data']['src']# 
    print(m4a_url)# 请求音频数据
    m4a_data = requests.get(url=m4a_url, headers=headers).content
    
    new_title = '卖吊票_岳云鹏郭德纲.m4a'
    print(new_title)
    # 4.数据持久化(保存)
    with open('video\\' + new_title, mode='wb') as f:
        f.write(m4a_data)
    print('保存完成:', new_title)
    
    	
    
    
    • 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

    在这里插入图片描述

  • 相关阅读:
    C++ 移动构造函数详解
    python装饰器
    【iptables 实战】01 iptables概念
    Practicing Version Control
    通过java爬取动态网页
    声网,站在物联网的“土壤”里
    spring boot单元测试之druid NullPointException问题解决
    Linux基础操作
    轻松整理文件夹,将视频文件全部归类到另一个文件夹!
    springBoot整合SqlSessionTemplate使用
  • 原文地址:https://blog.csdn.net/nalanxiaoxiao2011/article/details/133349965