Skip to content

Instantly share code, notes, and snippets.

@whexy
Created February 18, 2022 09:24
Show Gist options
  • Save whexy/f513a37eaa9059c330a21c738e4228b3 to your computer and use it in GitHub Desktop.
Save whexy/f513a37eaa9059c330a21c738e4228b3 to your computer and use it in GitHub Desktop.
Get snapshot of webpage use selenium and headless chrome
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
# Chrome Service with driver
CHROMEDRIVER_PATH = '/usr/bin/chromedriver'
service = Service(CHROMEDRIVER_PATH)
# Chrome Options with headless
options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
# Visit Webpage
driver = webdriver.Chrome(service=service, options=options)
driver.get("https://www.whexy.com")
# Get Screenshot
driver.get_screenshot_as_file("screenshot.png")
driver.quit()
@whexy
Copy link
Author

whexy commented Feb 18, 2022

Successfully use this script to grab snapshots on my Raspberry pie. The trick is to disable GPU. 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment