I am trying to scrape images from a webcam using the python module Selenium, but I am running into a problem that the video does not play automatically. So I always screenshot the paused video. Does anyone have ideas how to press play on the webcam video before the screenshot is taken?
from selenium import webdriver
import time
DRIVER = 'chromedriver'
driver = webdriver.Chrome('/usr/local/bin/chromedriver')
driver.maximize_window()
driver.get('https://arboretum-camera.vmhost.psu.edu/#view')
time.sleep(5) # wait for X seconds before taking screenshot
screenshot = driver.save_screenshot('test_screenshot.png')
driver.quit()
Just click the Play button
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
wait = WebDriverWait(driver, 30)
wait.until(EC.element_to_be_clickable((By.ID, "playIcon")))
driver.find_element_by_id("playIcon").click()
alternatively:
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#playIcon")))
driver.find_element_by_css_selector("#playIcon").click()
Addition:
You don't really need this: DRIVER = 'chromedriver'
Here driver = webdriver.Chrome('/usr/local/bin/chromedriver')
you defined it correctly.