Screenshot Options

Screenshot specific screen dimensions, full page or just a particular CSS selector.

With BrowserAPI, you can customise the screenshot by adding screenshot_options to your request. The value of this parameter should be a stringified object and the currently supported keys for this object are:

Screenshot Options Integration Examples

#1: Full Page Screenshot

The full GET request for the full_page screenshot should be:

https://api.webscrapingapi.com/v1?api_key=<YOUR_API_KEY>&url=https://httpbin.org/&render_js=1&screenshot=1&screenshot_options==%7B%22full_page%22%3A%221%22%7D%0A"
curl "https://api.webscrapingapi.com/v1\?api_key\=<YOUR_API_KEY>\&url\=https://httpbin.org\&render_js\=1\&screenshot\=1\&screenshot_options\=%7B%22full_page%22%3A%221%22%7D%0A"

Important! The url parameter has to be encoded. ( i.e. &url=https%3A%2F%2Fwww.webscrapingapi.com%2F )

Response Example
{
    "screenshot": "/9j/4AAQSkZJRgABAQAAAQABAAD/4gIoSUNDX1BST0ZJTEUAAQEAAAIYAAAAAAQwAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAA...
}

#2: Screenshot Specific CSS Selector

The full GET request for the screenshot_selector screenshot should be:

https://api.webscrapingapi.com/v1?api_key=<YOUR_API_KEY>&url=https://httpbin.org/&render_js=1&screenshot=1&screenshot_options={"screenshot_selector":"$selector"}
curl https://api.webscrapingapi.com/v1?api_key=<YOUR_API_KEY>&url=https://httpbin.org/&render_js=1&screenshot=1&screenshot_options='\{"screenshot_selector":".logo"\}'
Response Example
{
    "screenshot": "/9j/4AAQSkZJRgABAQAAAQABAAD/4gIoSUNDX1BST0ZJTEUAAQEAAAIYAAAAAAQwAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAA...
}

#3: Custom Viewport Size

The full GET request with custom width and height screenshot should be:

https://api.webscrapingapi.com/v1?api_key=<YOUR_API_KEY>&url=https://httpbin.org/&render_js=1&screenshot=1&screenshot_options={"width":"$size","height":"$size"}
curl https://api.webscrapingapi.com/v1?api_key=<YOUR_API_KEY>&url=https://httpbin.org/&render_js=1&screenshot=1&screenshot_options='\{"width":"$size","height":"$size"\}'
Response Example
{
    "screenshot": "/9j/4AAQSkZJRgABAQAAAQABAAD/4gIoSUNDX1BST0ZJTEUAAQEAAAIYAAAAAAQwAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAA...
}

#4: Return HTML

The full GET request that will return_html should be:

https://api.webscrapingapi.com/v1?api_key=<YOUR_API_KEY>&url=https://httpbin.org/&render_js=1&screenshot=1&screenshot_options={"return_html":"1"}
curl https://api.webscrapingapi.com/v1?api_key=<YOUR_API_KEY>&url=https://httpbin.org/&render_js=1&screenshot=1&screenshot_options='\{"return_html":"1"\}'
Response Example
{
    "screenshot": "/9j/4AAQSkZJRgABAQAAAQABAAD/4gIoSUNDX1BST0ZJTEUAAQEAAAIYAAAAAAQwAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAA...
}

What is a stringified object?

We define a stringified object as an object wrapped between quotation marks. For example, in this Python code, the stringified object is available on line 13:

import requests

API_KEY = '<YOUR_API_KEY>'
SCRAPER_URL = 'https://api.webscrapingapi.com/v1'

TARGET_URL = 'https://www.webscrapingapi.com/'

PARAMS = {
    "api_key":API_KEY,
    "url": TARGET_URL,
    "render_js":1,
    "screenshot":1,
    "screenshot_options":'{"<KEY>":"<VALUE>"}'
}

response = requests.get(SCRAPER_URL, params=PARAMS)
print(response.text) 

If you are using cURL to make your request, make sure to escape the curly brackets in order for your request to pass: &screenshot_options='\{"full_page":"1"\}'.

Last updated