Created
November 7, 2017 13:27
-
-
Save deeplook/48001bec95e877eecc9eabb26035f7d2 to your computer and use it in GitHub Desktop.
Snippet for making a screenshot of a webpage in a browser.
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 characters
| 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