-
-
Save MasterSwift/d0b42cc3f99a534328a95b04408df9e4 to your computer and use it in GitHub Desktop.
Revisions
-
jefftriplett created this gist
Oct 27, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ """ To install: # python requirements $ pip install click selenium # for headless chrome $ brew install chromedriver To use: $ python capture.py https://revsys.com revsys.png """ import click import time from selenium import webdriver from selenium.webdriver.chrome.options import Options @click.command() @click.option('--delay', default=1, help='Delay before capturing screenshot') @click.option('--headless/--no-headless', default=True, help='Run in headless mode') @click.option('--height', default=512, help='Browser height') @click.option('--width', default=1024, help='Browser width') @click.option('--zoom', default=100, help='Zoom level') @click.argument('url') @click.argument('filename') def capture(url, filename, delay, headless, height, width, zoom): chrome_options = Options() if headless: chrome_options.add_argument('--headless') chrome_options.add_argument(f'window-size={width}x{height}') driver = webdriver.Chrome( '/usr/local/bin/chromedriver', chrome_options=chrome_options ) driver.get(url) if zoom != 100: driver.execute_script(f"document.body.style.zoom='{zoom}%'") time.sleep(delay) driver.save_screenshot(filename) driver.quit() if __name__ == '__main__': capture()