diff --git a/docs/cloud/agent/structured-output.mdx b/docs/cloud/agent/structured-output.mdx index 9a0abe0b..12f726b2 100644 --- a/docs/cloud/agent/structured-output.mdx +++ b/docs/cloud/agent/structured-output.mdx @@ -55,3 +55,75 @@ for (const post of result.output.posts) { } ``` + +## Scrape multiple sites concurrently + +Each `client.run()` call creates its own session, so you can run them in parallel with `asyncio.gather` (Python) or `Promise.all` (TypeScript). Every result is fully typed. + + +```python Python +import asyncio +from browser_use_sdk.v3 import AsyncBrowserUse +from pydantic import BaseModel + +class Product(BaseModel): + name: str + price: str + url: str + +class Results(BaseModel): + products: list[Product] + +async def main(): + client = AsyncBrowserUse() + + sites = [ + "Find the top 3 laptops on amazon.com with their prices", + "Find the top 3 laptops on bestbuy.com with their prices", + "Find the top 3 laptops on newegg.com with their prices", + ] + + results = await asyncio.gather(*[ + client.run(task, output_schema=Results) + for task in sites + ]) + + for result in results: + for p in result.output.products: + print(f"{p.name} — {p.price}") + +asyncio.run(main()) +``` +```typescript TypeScript +import { BrowserUse } from "browser-use-sdk/v3"; +import { z } from "zod"; + +const Product = z.object({ + name: z.string(), + price: z.string(), + url: z.string(), +}); + +const Results = z.object({ + products: z.array(Product), +}); + +const client = new BrowserUse(); + +const sites = [ + "Find the top 3 laptops on amazon.com with their prices", + "Find the top 3 laptops on bestbuy.com with their prices", + "Find the top 3 laptops on newegg.com with their prices", +]; + +const results = await Promise.all( + sites.map((task) => client.run(task, { schema: Results })) +); + +for (const result of results) { + for (const p of result.output.products) { + console.log(`${p.name} — ${p.price}`); + } +} +``` + diff --git a/docs/cloud/llms.txt b/docs/cloud/llms.txt index a7a70418..492c16dc 100644 --- a/docs/cloud/llms.txt +++ b/docs/cloud/llms.txt @@ -21,6 +21,19 @@ export BROWSER_USE_API_KEY=bu_your_key_here ``` +Concurrent scraping — each `run()` creates its own session, so run them in parallel: +```python +results = await asyncio.gather(*[ + client.run(task, output_schema=MySchema) + for task in ["Scrape site A", "Scrape site B", "Scrape site C"] +]) +``` +```javascript +const results = await Promise.all( + tasks.map((task) => client.run(task, { schema: MySchema })) +); +``` + ## Get Started - [Quick start](https://docs.browser-use.com/cloud/quickstart): State-of-the-art AI browser automation with stealth browsers, CAPTCHA solving, residential proxies, and managed infrastructure. - [Prompt for Vibecoders](https://docs.browser-use.com/cloud/vibecoding): Complete Cloud SDK reference for AI coding agents. diff --git a/docs/llms.txt b/docs/llms.txt index a7a70418..492c16dc 100644 --- a/docs/llms.txt +++ b/docs/llms.txt @@ -21,6 +21,19 @@ export BROWSER_USE_API_KEY=bu_your_key_here ``` +Concurrent scraping — each `run()` creates its own session, so run them in parallel: +```python +results = await asyncio.gather(*[ + client.run(task, output_schema=MySchema) + for task in ["Scrape site A", "Scrape site B", "Scrape site C"] +]) +``` +```javascript +const results = await Promise.all( + tasks.map((task) => client.run(task, { schema: MySchema })) +); +``` + ## Get Started - [Quick start](https://docs.browser-use.com/cloud/quickstart): State-of-the-art AI browser automation with stealth browsers, CAPTCHA solving, residential proxies, and managed infrastructure. - [Prompt for Vibecoders](https://docs.browser-use.com/cloud/vibecoding): Complete Cloud SDK reference for AI coding agents.