How to Take a Screenshot of a URL using Python

Rendering an image of a website’s home page serves a variety of uses. Chiefly, it’s an easy way to store images of how your website & various accounts appear to the average page visitor. To gather website screenshots efficiently, you can leverage our URL Screenshot API as a built-in service for your application or website. It will simply generate a full-page screenshot PNG image of the website in question and return the file for use in whichever way you see fit.

Below, I’ll demonstrate how you can easily structure your API in Python using ready-to-run code examples.

Let’s start by installing the Python SDK. Run the following command:

pip install cloudmersive-convert-api-client

Next, let’s copy in the imports:

from __future__ import print_function
import time
import cloudmersive_convert_api_client
from import ApiException
from pprint import pprint

After that, copy the remaining code to call the function. You’ll need a Cloudmersive API key to authenticate within the first snippet (you can get one easily by registering a free account on our website).

# Configure API key authorization: Apikey
configuration = cloudmersive_convert_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = cloudmersive_convert_api_client.ConvertWebApi(cloudmersive_convert_api_client.ApiClient(configuration))
input = cloudmersive_convert_api_client.ScreenshotRequest() # ScreenshotRequest | Screenshot request parameters
# Take screenshot of URL
api_response = api_instance.convert_web_url_to_screenshot(input)
except ApiException as e:
print("Exception when calling ConvertWebApi->convert_web_url_to_screenshot: %s\n" % e)

With that, you’re all done — no more coding required.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.