如何使用Python进行下载对应的视频地址

如何使用Python进行下载对应的视频地址

下载 视频地址

python 复制代码
import requests


def download_video(video_url, save_path):
    try:
        response = requests.get(video_url)
        if response.status_code == 200:
            with open(save_path, 'wb') as f:
                f.write(response.content)
            print(f"视频下载成功,保存至 {save_path}")
        else:
            print(f"下载失败,状态码: {response.status_code}")
    except requests.exceptions.RequestException as e:
        print(f"下载过程出现错误: {e}")


if __name__ == "__main__":
    video_url = "这里替换为你实际获取到的视频地址"
    save_path = "video.mp4"  # 可以根据需要修改保存的文件名和路径
    download_video(video_url, save_path)

批量处理

python 复制代码
import certifi
import requests
import csv


def read_csv(csvfile):
    urls=[]
    # 打开csv文件
    with open(csvfile, mode='r', newline='') as file:
        # 创建csv读取器
        csvR = csv.reader(file)
        # 遍历每一行,跳过第一行
        for row in csvR:
            url = row[0]
            urls.append(url)
    # urls = list(set(urls))
    unique_list = []
    for i in urls:
        if i not in unique_list:
            unique_list.append(i)
    print(unique_list)
    return unique_list

def write_csv(csvfileW,dataW):
    # 打开csv文件以写入模式
    with open(csvfileW, mode='w', newline='') as fileW:
        # 创建csv写入器
        csvW = csv.writer(fileW)
        # 写入数据
        for row in dataW:
            csvW.writerow(row)

def download_video(video_url, save_path):
    try:
        # response = requests.get(video_url,verify=certifi.where())
        response = requests.get(video_url,verify=False)
        if response.status_code == 200:
            with open(save_path, 'wb') as f:
                f.write(response.content)
            print(f"视频下载成功,保存至 {save_path}")
        else:
            print(f"下载失败,状态码: {response.status_code}")
    except requests.exceptions.RequestException as e:
        print(f"下载过程出现错误: {e}")




if __name__ == "__main__":
    urls = read_csv(r'fiddler.csv')

    n = 0
    for video_url in urls:
        n+=1
        save_path = r"{}.mp4".format(n)
        download_video(video_url, save_path)
相关推荐
树獭非懒13 小时前
AI大模型小白手册|Embedding 与向量数据库
后端·python·llm
唐叔在学习17 小时前
就算没有服务器,我照样能够同步数据
后端·python·程序员
曲幽18 小时前
FastAPI流式输出实战与避坑指南:让AI像人一样“边想边说”
python·ai·fastapi·web·stream·chat·async·generator·ollama
Flittly19 小时前
【从零手写 AI Agent:learn-claude-code 项目实战笔记】(1)The Agent Loop (智能体循环)
python·agent
vivo互联网技术20 小时前
ICLR2026 | 视频虚化新突破!Any-to-Bokeh 一键生成电影感连贯效果
人工智能·python·深度学习
敏编程21 小时前
一天一个Python库:virtualenv - 隔离你的Python环境,保持项目整洁
python
喝茶与编码1 天前
Python异步并发控制:asyncio.gather 与 Semaphore 协同设计解析
后端·python
zone77391 天前
003:RAG 入门-LangChain 读取图片数据
后端·python·面试
用户8356290780511 天前
在 PowerPoint 中用 Python 添加和定制形状的完整教程
后端·python