import requests

def download_video(url, filename):
    try:
        # 发起请求，设置stream=True以流式下载
        response = requests.get(url, stream=True)
        response.raise_for_status()  # 检查请求是否成功

        # 以二进制写入模式打开文件
        with open(filename, 'wb') as f:
            # 逐块写入数据，chunk_size可调整
            for chunk in response.iter_content(chunk_size=8192):
                if chunk:
                    f.write(chunk)
        print(f"视频已成功下载到：{filename}")
    except Exception as e:
        print(f"下载过程中出现错误：{e}")