第一种方法:使用 requests 库和正则表达式

1. 使用 requests 库发送请求获取视频页面源码

使用 requests 库发送 GET 请求,获取视频页面的源码:

import requests

url = "视频页面的 URL"
response = requests.get(url)
html = response.text
Python

2. 使用正则表达式提取无水印视频链接

通过分析视频页面的源码,使用正则表达式提取无水印的视频链接:

import re

pattern = r'videoUrl":"(.*?)"'
video_url = re.findall(pattern, html)[0]
Python

3. 下载无水印视频

使用 requests 库发送 GET 请求,下载无水印的视频:

video_response = requests.get(video_url)
with open(" 无水印视频 .mp4", "wb") as f:
    f.write(video_response.content)
Python

第二种方法:使用 BeautifulSoup 库

1. 使用 BeautifulSoup 解析视频页面

使用 BeautifulSoup 库解析视频页面的源码:

from bs4 import BeautifulSoup
import requests

url = "视频页面的 URL"
response = requests.get(url)
html = response.text
soup = BeautifulSoup(html, "html.parser")
Python

2. 使用 BeautifulSoup 提取无水印视频链接

通过分析视频页面的结构,使用 BeautifulSoup 提取无水印的视频链接:

video_element = soup.find("video")
video_url = video_element["src"]
Python

3. 下载无水印视频

使用 requests 库发送 GET 请求,下载无水印的视频:

video_response = requests.get(video_url)
with open(" 无水印视频 .mp4", "wb") as f:
    f.write(video_response.content)
Python

第三种方法:使用第三方库如 you-get

1. 安装 you-get 库

使用 pip 命令安装 you-get 库:

pip install you-get
Bash

2. 下载无水印视频

使用 you-get 库提供的命令行工具下载无水印的视频:

you-get -o ./videos --no-caption "视频页面的 URL"
Bash

其中,-o 参数指定下载目录,--no-caption 参数表示不下载字幕。

you-get 库是一个强大的视频下载工具,支持多个视频网站,使用简单方便。