How to screenshot a website/URL in Python

Today we will be using our conversion API to easily take a screenshot of a URL. First we need to use pip install to add our client:

pip install git+https://github.com/Cloudmersive/Cloudmersive.APIClient.Python.Convert.git

Then we just have to call convert_web_url_to_screenshot:

from __future__ import print_function
import time
import cloudmersive_convert_api_client
from cloudmersive_convert_api_client.rest import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_convert_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['Apikey'] = 'Bearer'
# 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
try:
# Take screenshot of URL
api_response = api_instance.convert_web_url_to_screenshot(input)
pprint(api_response)
except ApiException as e:
print("Exception when calling ConvertWebApi->convert_web_url_to_screenshot: %s\n" % e)

And that’s it! Let’s say we put in https://www.google.com/ our resulting screenshot will look like this:

Image for post
Image for post

Written by

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

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