Getting Started with Pyppeteer

This article will walk you through the process of leveraging BrowserCat and Pyppeteer for browser automation at scale.

Prerequisites

Before you get started, you’ll need to:

  1. Sign up for a free BrowserCat account.
  2. Create an API key.
  3. Install Pyppeteer in your project…
pip install pyppeteer

Your first automation

The following script connects to a BrowserCat browser, navigate to a website, and print the page title.

With a little tweaking (and the Pyppeteer docs), you can automate literally anything you can do in a real browser.

import asyncio
from pyppeteer import connect

bcatUrl = 'wss://api.browsercat.com/connect'

async def run():
    # Create a new browser instance
    browser = await connect({
        'browserWSEndpoint': bcatUrl,
        'headers': {
            'api-key': '<YOUR_API_KEY>'
        }
    })

    # Do stuff...
    page = await browser.newPage()
    await page.goto('https://example.com')
    print(await page.title())

    # Close the browser when you're done
    await browser.close()

asyncio.get_event_loop().run_until_complete(run())

Configure the browser

It’s really easy to configure our browsers for your needs. Whether you want to connect to a specific region, set up a third-party proxy, or customize your browser launch args, we’ve got you covered.

See out browser config docs for more info.