• 下载梨视频


    import time
    import requests
    
    
    # 返回视频的真实下载地址
    def get_real_video_url(video_id):
        # 视频地址解析接口
        url = 'https://www.pearvideo.com/videoStatus.jsp?contId={}'.format(video_id)
        headers = {
            'Referer': 'https://www.pearvideo.com/video_{}'.format(video_id),  # 防盗链,溯源这次请求的上一次请求的url
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'
        }
        response = requests.get(url, headers=headers)
        system_time = response.json()['systemTime']
        # 假链接 https://video.pearvideo.com/mp4/adshort/20211111/1637987795364-15793700_adpkg-ad_hd.mp4
        fake_src_url = response.json()['videoInfo']['videos']['srcUrl']
        # 真链接 https://video.pearvideo.com/mp4/adshort/20211111/cont-1746412-15793700_adpkg-ad_hd.mp4
        real_src_url = fake_src_url.replace(system_time, 'cont-{}'.format(video_id))
        return real_src_url
    
    
    def download_video(url):
        video_id = url.split('-')[1]
        # file_name = str('.\\Video\\') + str(video_id) + '.mp4'
        file_name = str(video_id) + '.mp4'
        try:
            with open(file_name, mode='wb') as f:
                f.write(requests.get(url).content)
            print(video_id, 'success')
        except:
            print(video_id, 'error')
    
    
    if __name__ == '__main__':
        # url = input('输入视频的url:')
        start = time.time()
        url = 'https://www.pearvideo.com/video_1746036'
        v_id = url.split('_')[1]
        real_url = get_real_video_url(v_id)
        download_video(real_url)
        end = time.time()
        print('用时{:.2f}秒'.format(end - start))
    
  • 相关阅读:
    上海社保,统筹内不能转出的疑惑
    c# 代理IP获取通用方法
    element-ui 的el-button组件中添加自定义颜色和图标的实现方法
    前端实现打印功能
    elementUI表格合并单元格
    webpack打包图片资源找不到问题
    Webstorm/IntelliJ Idea 过期破解方法
    ES6 Promise 用法讲解
    移动端开发
    Stylus的基础用法
  • 原文地址:https://www.cnblogs.com/xuecl/p/15641402.html
Copyright © 2020-2023  润新知