I'm trying to have a Docker on my NAS running every 3-4 hours taking a screenshot of a website. Unfortunately, I'm not that familiar with Docker, and I have been searching online and trying to find images that already do what I want without much success. Some work, some others don't, and all the other threads I found here, didn't work either - maybe it was my own fault!
Here is my Python script:
from selenium import webdriver
import time
from datetime import datetime
from selenium.webdriver.support.ui import WebDriverWait # for implicit and explict waits
from selenium.webdriver.chrome.options import Options # for suppressing the browser
import ctypes
ctypes.windll.user32.ShowWindow( ctypes.windll.kernel32.GetConsoleWindow(), 0 )
option = webdriver.ChromeOptions()
option.add_argument('headless')
option.add_argument("--window-size=1920,1080")
CHROME_DRIVER_PATH = (
"...\chromedriver.exe"
)
URL = "https://www.example.com"
IMAGE_EXT = ".png"
def get_web_driver(driver_path: str) -> webdriver:
return webdriver.Chrome(driver_path, options=option)
def open_url(web_driver: webdriver, url: str) -> None:
# opens the given URL
return web_driver.get(url)
def screen_shot_webpage(web_driver: webdriver) -> None:
time.sleep(3)
web_driver.get_screenshot_as_file(get_date_today() + IMAGE_EXT)
def get_date_today() -> str:
now = datetime.now()
dt_string = now.strftime("%d-%m-%Y %H %M")
return str(dt_string)
def close_driver(web_driver) -> None:
web_driver.close()
def main():
chrome_driver = get_web_driver(CHROME_DRIVER_PATH)
open_url(chrome_driver, URL)
screen_shot_webpage(chrome_driver)
close_driver(chrome_driver)
if __name__ == "__main__":
main()
I tried creating my own Dockerfile and it was kind of a disaster. I also tried a couple of alternatives from this post to no avail: Docker image with python3, chromedriver, chrome & selenium
Does anyone have a simple solution for this or is it very complicated? My programming knowledge is very limited :/
Thanks in advance!!