DEV Community

vøiddo
vøiddo

Posted on Originally published at voidd0.github.io

Website screenshot API: how to turn a URL into a PNG, JPEG or WEBP image (Python, cURL, no code)

Capture a public web page as a PNG, JPEG or WEBP image: any viewport size, full page, retina scaling, optional cookie-banner hiding.

This tutorial shows what the Actor v0iddo/url-screenshot returns, how to run it on the Apify Store without code, and how to call it from Python and cURL.

What data you get

One row per result. Every row can be downloaded as JSON, CSV, Excel or HTML, or read through the API.

Field Label Type Example
index # number 0
file_url File URL https://api.apify.com/v2/key-value-stores/Gmq1hy2PAfT6TQ7Bt/records...
filename File name text screenshot.png
mime Type text image/png
bytes Bytes number 71152
credits Credits number 3
ms Time (ms) number 1283
file_key file_key text result-001-screenshot.png
width width number 1280
height height number 800
format format text png
final_url final_url text https://example.com/
http_status http_status number 200
title title text Example Domain
load_state load_state text networkidle
truncated truncated true/false false
blocked_requests blocked_requests number 0

Real rows from a run of the Actor (fields that name people are left out):

[
  {
    "index": 0,
    "file_url": "https://api.apify.com/v2/key-value-stores/Gmq1hy2PAfT6TQ7Bt/records/result-001-screenshot.png?signature=1zfATwZwqmmlfl8OgA6Um",
    "file_key": "result-001-screenshot.png",
    "filename": "screenshot.png",
    "mime": "image/png",
    "bytes": 71152,
    "width": 1280,
    "height": 800,
    "format": "png",
    "final_url": "https://example.com/",
    "http_status": 200,
    "title": "Example Domain",
    "load_state": "networkidle",
    "truncated": false,
    "blocked_requests": 0,
    "credits": 3,
    "ms": 1283
  }
]
Enter fullscreen mode Exit fullscreen mode

No code: run it on the Apify Store

  1. Open the Website screenshot API page on Apify.
  2. Fill in the input form. An example input is already filled in.
  3. Press Start, wait for the run to finish, and download the results as JSON, CSV or Excel from the Output tab.

The input that is pre-filled on the Actor page:

{
  "url": "https://example.com"
}
Enter fullscreen mode Exit fullscreen mode

Ready-made examples

Saved inputs on Apify: run one as it is, or copy it and change the values.

Python (apify-client)

Get your API token in Apify Console under Settings, then Integrations. The Actor id is v0iddo/url-screenshot.

from apify_client import ApifyClient

client = ApifyClient("YOUR_APIFY_TOKEN")

run_input = {'url': 'https://example.com'}

run = client.actor("v0iddo/url-screenshot").call(run_input=run_input)
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)
Enter fullscreen mode Exit fullscreen mode

cURL

curl -X POST "https://api.apify.com/v2/acts/v0iddo~url-screenshot/run-sync-get-dataset-items" \
  -H "Authorization: Bearer YOUR_APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com"}'
Enter fullscreen mode Exit fullscreen mode

Price

$3.40 per 1,000 results. You pay per result row. There is no separate charge per run. Higher Apify plans pay less per result, down to $2.38 per 1,000.

FAQ

What data does the Website screenshot API return?

Each result is one row in an Apify dataset. Fields include index, file_url, filename, mime, bytes, credits, ms, file_key, and more. The table above shows every field with an example value.

Can I use it without writing code?

Yes. Open the Actor page on Apify, fill in the input form (an example is already filled in), press Start, and download the results as JSON, CSV, Excel or HTML. You can also schedule runs there.

How much does it cost?

$3.40 per 1,000 results. You pay per result row. There is no separate charge per run. Higher Apify plans pay less per result, down to $2.38 per 1,000. A new Apify account gets $5 of platform credit every month.

Links

Top comments (0)