This short post show how Python can be used for taking multiple screnshots. The post will include:
- collecting the target URL-s
- format the URL-s
- take screenshots with Selenium
Step 1: Collect URL-s
For the URL collection we are going to use Chrome extension named: Scraper
Note that it might work only in older versions of Chrome or browsers like Vivaldi or Brave!
Step 2: Format the URL-s
For this step we can use:
- Excel
- Google Sheets
- Sublime + multine editing
The final goal is to prepare list as follows:
urls = [
    ['https://en.wikipedia.org/wiki/Wikipedia:Community_portal','Community portal'],
    ['https://en.wikipedia.org/wiki/Wikipedia:Village_pump','Community portal']..
]
Or Google Sheet formula as follows:
="['"&A2&", 'https://en.wikipedia.org"&B2&"],"
Step 3: Take a single screenshot
To take single screenshot we will use the following code:
from selenium import webdriver 
options = webdriver.ChromeOptions() 
driver = webdriver.Chrome(options=options)
driver.get("https://www.example.com")
driver.save_screenshot('~/Downloads/responsive.png')
or the display the image in Jupyterlab:
from IPython import display
from base64 import b64decode
def get_image(url, name):
    driver.get(url)
    driver.save_screenshot(f'~/Downloads/{name}.png')
img = driver.get_screenshot_as_base64()
display.Image(b64decode(img),width=1000)
Step 4: Take multiple screenshots
The code for taking multiple images once the list is prepared is:
Install selenium:
pip install selenium
Get single screenshot:
import time
for url_pair in urls:
    url = url_pair[0]
    name = url_pair[1]
    print(name)
    time.sleep(5)
    get_image(url, name)
note if you need to login before taking the screenshot you can load the page by:
driver.get("https://wikipedia.org/")
Full code
Take Screenshots in Python.ipynb
 
                     
                         
                         
                         
                         
                         
                         
                         
                        