From time to time, whether you need screenshots for web scraping, monitoring user or competitor behavior, or any other use case, you might need to take screenshots automatically. And, often, you’ll need to take them in bulk.
So in this post, we’ll show you how to automate screenshots quickly and easily through code and no-code methods.
Before you choose an automated screenshot tool, know your why. Your reason for needing automated screenshots will dictate the functionality you need.
And more! These are just a few examples. If you often need to save website screenshots, it’s much better to automate the task than waste hours doing it manually.
Now that we’ve seen why you’d want to automate screenshots, let’s look at how you can do it. Here, we’ll look at a few options you might consider, depending on your requirements.
One of the simplest ways to automate website screenshots is by using one of the many browser extensions, tools, and APIs available.
Luckily, there are tons of screenshot tools available, so you won’t have any difficulty finding one that meets your needs.
To get you off to a good start, here are some of the best options you can consider:
While not as simple as using a tool or extension, using code to automate website screenshots sometimes gives you more customization options.
More importantly, when you use code, you can implement screenshot features and functionality into your apps. You can use libraries or modules provided by programming languages themselves, or you can use pre-developed APIs.
For instance, you can use the pyautogui module to take a screenshot in Python. Here is the code you’ll use to do this:
This code takes a screenshot and saves it in the location provided. Quite simple, right? The problem is that, with this method, you’ll need to manually navigate to every screenshot you’d like to take.
This is a much better alternative:
There are a few simple ways to use ScreenshotAPI as your programmatic screenshot-taking tool. You can always manually request screenshots, but if you’re an advanced user, you’ll love the simple integration.
Once again, we’ll use Python.
To start, you’ll need to do some preparation, similar to our previous post. So, import the parse and request modules of Python’s urllib package with the following code:
import urllib.parse
import urllib.request
Then import Python’s ssl module with the code:
import ssl
The ssl module gives you access to Transport Layer Security encryption and peer authentication facilities for network sockets. When you’ve imported the ssl module, you can create an unverified SSLContext object, which allows you to access websites without valid SSL certificates:
ssl._create_default_https_context = ssl._create_unverified_context
Next, you’ll set the variables you’ll use to construct the query parameters. First, define the token variable, which is a string containing your ScreenshotAPI API key:
token = “Your API Key”
Then set the width and height of your target render. These are both integers:
width = 1920
height = 1080
Remember, you don’t have to use the same numbers we’ve used here; you can choose those that best meet your needs. You’ll then also define your output variable, a string that specifies the output format, either as an image or in JSON format. In this case, we’ll output images:
output = “image”
We haven’t set our url variable because we’ll do so when we deal with the different methods for automating screenshots.
The first method, a Python list, is probably the simplest of all the techniques we’ll use. To start, you’ll put all the websites you want to take screenshots of in a Python list. We’ll use a few search engines and news sites in our example.
url_list = [“www.google.com”, “www.yahoo.com”,”www.skynews.com”, “www.cnn.com”, “www.msn.com”]
Next, we’ll iterate through the list using a For loop, and with each iteration, we’ll set the url variable, construct the query parameters, and call the API:
for item in url_list:
url = item
query = "https://shot.screenshotapi.net/screenshot"
query += "?token=%s&url=%s&width=%d&height=%d&output=%s" % (token, url, width, height, output)
urllib.request.urlretrieve(query, "./screenshot.png")
This script will iterate through your entire list and take and save a screenshot for every website on your list.
While the list method mentioned above can be effective, it could become quite cumbersome if you have a lot of websites you want to take screenshots of.
Don’t worry, you don’t run it separately every single time - we wouldn’t want you falling asleep on us!
Instead, you just use a text file.
Let’s say you have a text file, saved as urllist.txt, with the following content:
www.google.com
www.yahoo.com
www.skynews.com
www.cnn.com
www.msn.com
You'll use the same process described above, but you’ll first need to open the file for Python to read it. To do this, you’ll use the with statement with open and set the mode to r for reading:
with open(“urllist.txt”, ”r”) as url_file:
With the file open, you’ll again use a for loop to iterate through the items in your text file:
for line in url_file:
With each iteration, you’ll set the url variable, strip the end-line break from the line, construct the query parameters, and call the API:
url = line.strip()
query = "https://shot.screenshotapi.net/screenshot"
query += "?token=%s&url=%s&width=%d&height=%d&output=%s" % (token, url, width, height, output)
urllib.request.urlretrieve(query, "./screenshot.png")
This script iterates through all the websites on your list, no matter how many, and takes a screenshot of each.
The methods described above work great if you want to take bulk screenshots of many sites, but what do you do if you want to take automatic screenshots of only one site?
This could, for example, be for employee or user monitoring.
One of the simplest ways to do this is using the time module. You’ll need to import the module during the setup stage mentioned earlier. You’ll also set your url variable, and you’ll construct your query during the setup process:
import time
…
url = “www.google.com”
…
query = "https://shot.screenshotapi.net/screenshot"
query += "?token=%s&url=%s&width=%d&height=%d&output=%s" % (token, url, width, height, output)
Next, you’ll use a while loop to let the code execute continuously, but with the sleep function to ensure that it only repeats in seconds after a given time period. For example, if you want a screenshot every ten minutes, your code will be:
while(True):
urllib.request.urlretrieve(query, "./screenshot.png")
time.sleep(600)
You can set this time period based on how often you want screenshots to be taken, and the script will then execute and save screenshots at these defined intervals.
Likewise, when using JavaScript to take screenshots, you’ll use this code:
You can also use code to take screenshots by using the ScreenshotAPI API in PHP, Java, and Ruby. (Click through to read our complete guides with code samples.)
Once you decide to use code to take screenshots, it’s time to automate the process.
For instance, you can use a list to take screenshots of several websites in succession. Here’s the Python code to do that:
This code will iterate through the list and call the API for every URL. Besides a list, you can also use a text or CSV file to automate your screenshots.
You can approach automation this way, regardless of your preferred programming language. However, remember that the language conventions and syntax will differ.
The simplest way to automate your screenshots is by using ScreenshotAPI’s No-Code Query Builder.
Enter the URL you’d like a screenshot of, and choose your required screenshot options.
Let’s assume you’d like to take a full-page screenshot and block any ads.
The first step is to log into Screenshot API and head over to the Query Builder.
Let’s say you’d like to take a screenshot of Amazon’s homepage in full high-definition resolution. So, you’ll enter those details into the query builder.
And remember, you want a full-page screenshot, so you’ll also select that option.
To block the ads, you’ll need to go to the advanced options by clicking Show Advanced Options. Here, you can choose the file and output type, set delays, scroll to specific elements, and more. To block the ads, you’ll check this box:
Once you’ve chosen all your options, you can take the screenshot by clicking Take Screenshot at the bottom of the page.
However, to automate your screenshots, you can copy the API query and use it in combination with code to get the screenshots you require.
In this example, based on your requirements, this would be your query:
Are you using no-code methods? You can easily take automated and periodic website screenshots with ScreenshotAPI, Make.com, and Google Drive.
Apart from blocking ads, there are a ton of other options available. So, the best way to learn about everything the query builder can do is to get started for free and play around with it.
And that’s it! ScreenshotAPI gives you plenty of ways to programmatically take screenshots (and choose the exact cadence that fits your workflow best). There’s no reason to jump through hoops anymore.
You’re one API key away from getting screenshots off your to-do list!
Head over to ScreenshotAPI to register a free account, or start using your account to get more mileage out of your automation and free up enough time to grab a cup of coffee (or two). 😊
But wait! Before we go – these are a few questions our customers often have when automating website screenshots:
You can easily automate the screenshot process using any of the above methods. To find the right one, you’ll need to consider your unique needs and requirements to figure out which way will be the best fit.
Considering that most websites implement this feature, you must be able to take scrolling screenshots. Fortunately, with ScreenshotAPI, taking scrolling screenshots is quite simple. You just have to log into the Query Builder and select this option, as we’ve described earlier.
Windows does not provide a native tool for taking screenshots from the command line. So, you’ll typically need a third-party application to take screenshots from the command line by executing a simple command.
Selenium is a tool that helps you automate several browser actions so that you can automate screenshots in Selenium easily. Our guide on the link explains how to use Selenium with Ruby.
Use ScreenshotAPI to take your screenshots, then integrate it with Make.com and create a workflow that automatically shares screenshots to your preferred channel. Need help? We wrote a complete guide with the steps explained!