DEV Community

Custodia-Admin
Custodia-Admin

Posted on • Edited on • Originally published at pagebolt.dev

How to take website screenshots in Python (without Selenium or Playwright)

How to Take Website Screenshots in Python (Without Selenium or Playwright)

The classic Python approach to website screenshots involves Selenium, a chromedriver binary, version pinning nightmares, and a CI pipeline that breaks every time Chrome updates. There's a simpler path.

A screenshot API call returns the PNG directly. Here's what that looks like in Python:

import requests

response = requests.post(
    'https://pagebolt.dev/api/v1/screenshot',
    headers={'x-api-key': 'YOUR_API_KEY'},
    json={'url': 'https://example.com', 'fullPage': True}
)

with open('screenshot.png', 'wb') as f:
    f.write(response.content)
Enter fullscreen mode Exit fullscreen mode

Five lines. No binary dependencies. Works in any Python environment — Lambda, Cloud Run, a Jupyter notebook, your local machine.

Full-page screenshots

response = requests.post(
    'https://pagebolt.dev/api/v1/screenshot',
    headers={'x-api-key': 'YOUR_API_KEY'},
    json={
        'url': 'https://yoursite.com',
        'fullPage': True,
        'fullPageScroll': True,  # triggers lazy-loaded images before capture
        'blockBanners': True     # removes cookie consent popups
    }
)
Enter fullscreen mode Exit fullscreen mode

fullPageScroll: True scrolls the page before capturing — this forces lazy-loaded images and infinite scroll content to render. blockBanners removes GDPR popups automatically.

Mobile screenshots

response = requests.post(
    'https://pagebolt.dev/api/v1/screenshot',
    headers={'x-api-key': 'YOUR_API_KEY'},
    json={
        'url': 'https://yoursite.com',
        'viewportDevice': 'iphone_14_pro',
        'fullPage': True
    }
)
Enter fullscreen mode Exit fullscreen mode

25+ device presets available. Useful for visual regression testing across breakpoints or generating mobile-specific previews.

Generate a PDF instead

Swap the endpoint:

response = requests.post(
    'https://pagebolt.dev/api/v1/pdf',
    headers={'x-api-key': 'YOUR_API_KEY'},
    json={
        'url': 'https://yoursite.com/report',
        'format': 'A4',
        'printBackground': True
    }
)

with open('report.pdf', 'wb') as f:
    f.write(response.content)
Enter fullscreen mode Exit fullscreen mode

Same pattern, same credentials.

Async batch screenshots

For scraping or monitoring pipelines that need many screenshots in parallel:

import asyncio
import aiohttp

async def screenshot(session, url, filename):
    async with session.post(
        'https://pagebolt.dev/api/v1/screenshot',
        headers={'x-api-key': 'YOUR_API_KEY'},
        json={'url': url, 'fullPage': True}
    ) as response:
        content = await response.read()
        with open(filename, 'wb') as f:
            f.write(content)

async def main():
    urls = [
        ('https://site-a.com', 'site-a.png'),
        ('https://site-b.com', 'site-b.png'),
        ('https://site-c.com', 'site-c.png'),
    ]
    async with aiohttp.ClientSession() as session:
        await asyncio.gather(*[screenshot(session, url, fn) for url, fn in urls])

asyncio.run(main())
Enter fullscreen mode Exit fullscreen mode

All three screenshots fire in parallel. No browser pool to manage.

Passing cookies for authenticated pages

response = requests.post(
    'https://pagebolt.dev/api/v1/screenshot',
    headers={'x-api-key': 'YOUR_API_KEY'},
    json={
        'url': 'https://app.yoursite.com/dashboard',
        'cookies': ['session=abc123; Domain=yoursite.com'],
        'fullPage': True
    }
)
Enter fullscreen mode Exit fullscreen mode

No chromedriver. No webdriver-manager. No Selenium grid. Just requests and an API key.

Try it free — 100 requests/month, no credit card. → Get started in 2 minutes

Top comments (0)