Browser

Control a browser directly in your Scrapybara instance with Playwright

1

Start an instance

1from scrapybara import Scrapybara
2
3client = Scrapybara(api_key="your_api_key")
4instance = client.start(instance_type="small")
2

Start a browser session

1cdp_url = instance.browser.start().cdp_url
3

Authenticate the session (optional)

To save the authenticated state of a browser session, use the saveAuth method.

1auth_state_id = instance.browser.save_auth(name="default").auth_state_id

Now, you can reuse the saved auth state on other instances by passing the auth_state_id to the authenticate method. The browser needs to be started first.

1instance.browser.authenticate(auth_state_id=auth_state_id)
4

Connect to the browser

1from playwright.sync_api import sync_playwright
2
3playwright = sync_playwright().start()
4browser = playwright.chromium.connect_over_cdp(cdp_url)
5

Interact with the browser

1page = browser.new_page()
2page.goto("https://scrapybara.com")
3screenshot = page.screenshot()
6

Stop the browser session

1instance.browser.stop()
Built with