Selenium 与 python。获取视频编解码器

问题描述 投票:0回答:1

我想扫描我的博客文章并检查所有视频是否具有相同的编解码器,如何在 selenium 上使用 python 实现这一点

from selenium import webdriver
  
browser = webdriver.Chrome()
browser.get(url)
video = browser.find_element(By.TAG_NAME, "video")

接下来会发生什么?

python selenium-webdriver video webdriver codec
1个回答
0
投票

如果您想查看博客页面中视频的

codec
。假设您的页面中只有一个视频。这是您应该尝试的代码..

from selenium import webdriver

browser = webdriver.Chrome()
browser.get(url)
video = browser.find_element(By.TAG_NAME, "video")


from selenium.webdriver.common.by import By
import requests
import tempfile
import os
from moviepy.editor import VideoFileClip

# Get the source URL of the video
video_url = video.get_attribute("src")

# Download the video temporarily
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
    response = requests.get(video_url)
    tmp_file.write(response.content)
    tmp_file.close()
    video_path = tmp_file.name

# Get the codec of the video
clip = VideoFileClip(video_path)
codec = clip.reader.infos['video']['codec_name']

# Close the video clip
clip.close()
# Remove the temporary video file
os.remove(video_path)

print("Codec of the video:", codec)

如果一篇博客文章中有多个视频,请使用

for
循环
for video in videos:
,如果您想扫描多个帖子,请创建
list
url,然后将其与 for 循环一起使用,将 url 发送到每个博客文章的代码。

# List of URLs to process
urls = [
    "url1",
    "url2",
    "url3",
    # Add more URLs as needed
]
for url in urls:
    # Rest of The selenium Code…

请随时发表评论以获取更多帮助,或者想要更多说明。

© www.soinside.com 2019 - 2024. All rights reserved.