Simple python function that provide you to take a whole web page screenshot from Selenium WebDriver using Pillow.
This functions save pages to files (more than 30 formats available).
I need this function for testing purposes, but I think it can be useful in another tasks.
Check work with:
- Firefox (with headless mode)
- Chrome (with headless mode)
State of driver after script execution will be the same as before.
from save_webpage import save_webpage
from selenium import webdriver
driver = webdriver.Chrome('./chromedriver')
driver.get('https://github.com/about')
save_webpage(driver, 'page.jpg')
driver.quit()
For windows in headless mode don't forget about --disable-gpu
key.
By default, script hide scroll bar. But you can manually disable it
from save_webpage import save_webpage
from selenium import webdriver
driver = webdriver.Chrome('./chromedriver')
driver.get('https://github.com/about')
save_webpage(driver, 'page.jpg', hide_scrollbar=False)
driver.quit()
from save_webpage import save_webpage
from selenium import webdriver
image_options = {
"format": "JPEG",
"quality": 80
}
driver = webdriver.Chrome('./chromedriver')
driver.get('https://github.com/about')
save_webpage(driver, 'page.jpg', **image_options)
driver.quit()
In this example shows how to save image in JPEG format with 80 quality (default parameters).
This functionality provided by PIL library. For more information see docs
- Check other webdrivers support
- Add inline use (?)