selenium 对chrome浏览器视频检测性能指标获取 python代码
时间: 2024-03-16 08:17:08 浏览: 131
Python 通过Selenium浏览器自动化测试框架获取HTML代码中的可用数据 Python源码
以下是使用selenium对chrome浏览器视频检测性能指标获取的Python代码示例:
```python
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# 设置Chrome浏览器驱动路径
chromedriver_path = '/path/to/chromedriver'
# 创建Chrome浏览器实例
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-extensions')
chrome_options.add_argument('--disable-infobars')
chrome_options.add_argument('--mute-audio')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-setuid-sandbox')
chrome_options.add_argument('--disable-logging')
chrome_options.add_argument('--disable-browser-side-navigation')
chrome_options.add_argument('--disable-web-security')
chrome_options.add_argument('--allow-running-insecure-content')
chrome_options.add_argument('--disable-remote-fonts')
chrome_options.add_argument('--start-maximized')
chrome_options.add_argument('--disable-notifications')
chrome_options.add_argument('--disable-popup-blocking')
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--disable-translate')
chrome_options.add_argument('--disable-default-apps')
chrome_options.add_argument('--disable-background-networking')
chrome_options.add_argument('--disable-background-timer-throttling')
chrome_options.add_argument('--disable-client-side-phishing-detection')
chrome_options.add_argument('--disable-component-update')
chrome_options.add_argument('--disable-hang-monitor')
chrome_options.add_argument('--disable-prompt-on-repost')
chrome_options.add_argument('--disable-sync')
chrome_options.add_argument('--disable-webgl')
chrome_options.add_argument('--hide-scrollbars')
chrome_options.add_argument('--ignore-gpu-blacklist')
chrome_options.add_argument('--incognito')
chrome_options.add_argument('--no-proxy-server')
chrome_options.add_argument('--use-gl=swiftshader')
service = Service(executable_path=chromedriver_path)
driver = webdriver.Chrome(service=service, options=chrome_options)
# 打开视频网站
driver.get('https://www.example.com')
# 等待视频元素加载完成
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//video'))
)
# 获取视频加载时间
load_time = driver.execute_script('return performance.timing.loadEventEnd - performance.timing.navigationStart;')
print(f'视频加载时间: {load_time}ms')
# 获取视频播放时间
play_time = driver.execute_script('return arguments[0].duration;', element)
print(f'视频播放时间: {play_time}s')
# 获取视频分辨率
video_width = driver.execute_script('return arguments[0].videoWidth;', element)
video_height = driver.execute_script('return arguments[0].videoHeight;', element)
print(f'视频分辨率: {video_width}x{video_height}')
# 获取视频帧率
video_fps = driver.execute_script('return window.getComputedStyle(arguments[0]).webkitFrameRate;', element)
print(f'视频帧率: {video_fps}fps')
# 关闭浏览器
driver.quit()
```
注意:以上代码仅供参考,具体实现可能需要根据实际情况进行调整。
阅读全文