Skip to content

Instantly share code, notes, and snippets.

@deeplook
Created November 7, 2017 13:27
Show Gist options
  • Select an option

  • Save deeplook/48001bec95e877eecc9eabb26035f7d2 to your computer and use it in GitHub Desktop.

Select an option

Save deeplook/48001bec95e877eecc9eabb26035f7d2 to your computer and use it in GitHub Desktop.
Snippet for making a screenshot of a webpage in a browser.
import re
from selenium import webdriver # pip install selenium
from PIL import Image # pip install Pillow
driver = webdriver.PhantomJS() # assuming PhantomJS
width, height = 1024, 768
driver.set_window_size(width, height)
driver.get("http://docs.python-requests.org")
fn = "screenshot.png"
driver.save_screenshot(fn)
img = Image.open(fn).crop((0, 0, width, height))
img.save(re.sub(".png$", "-cropped.png", fn))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment