Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
new docs for search API and examples
mertunsall2c5c74cab2db
diff --git a/docs/api-reference/search-url.mdx b/docs/api-reference/search-url.mdxnew file mode 100644index 000000000..17ab832df--- /dev/null+++ b/docs/api-reference/search-url.mdx@@ -0,0 +1,122 @@+---+title: "Search URL"+api: "POST https://api.browser-use.com/api/v1/search-url"+description: "Extract specific content from a given URL using AI"+---++## Overview++The Search URL endpoint extracts relevant content from a specific website URL based on your query. This is ideal for targeted content extraction, research on specific websites, or analyzing particular web pages.++π‘ **Complete working example**: [search_url.py](https://github.com/browser-use/browser-use/blob/main/examples/search/search_url.py)++## Request++<ParamField body="url" type="string" required>+ The URL to extract content from+</ParamField>++<ParamField body="query" type="string" required>+ What specific content to look for and extract from the URL+</ParamField>++<ParamField body="depth" type="integer" default="2">+ How deep to navigate within the website (2-5)+</ParamField>++## Response++<ResponseField name="url" type="string">+ The URL that was processed+</ResponseField>++<ResponseField name="content" type="string">+ Extracted content relevant to the search query+</ResponseField>++<ResponseExample>+```json Response+{+ "url": "https://example.com",+ "content": "Relevant content extracted from the website based on your query..."+}+```+</ResponseExample>++## Example++<RequestExample>+```python Python+import aiohttp+import asyncio++async def search_website():+ payload = {+ "url": "https://www.artificialintelligence-news.com/",+ "query": "Latest AI News",+ "depth": 2+ }++ headers = {+ "Authorization": "Bearer YOUR_API_KEY",+ "Content-Type": "application/json"+ }++ async with aiohttp.ClientSession() as session:+ async with session.post(+ "https://api.browser-use.com/api/v1/search-url",+ json=payload,+ headers=headers+ ) as response:+ return await response.json()++result = asyncio.run(search_website())+print(result)+```++```javascript JavaScript+const response = await fetch('https://api.browser-use.com/api/v1/search-url', {+ method: 'POST',+ headers: {+ 'Authorization': 'Bearer YOUR_API_KEY',+ 'Content-Type': 'application/json'+ },+ body: JSON.stringify({+ url: 'https://www.artificialintelligence-news.com/',+ query: 'Latest AI News',+ depth: 2+ })+});++const result = await response.json();+console.log(result);+```++```bash cURL+curl -X POST "https://api.browser-use.com/api/v1/search-url" \+ -H "Authorization: Bearer YOUR_API_KEY" \+ -H "Content-Type: application/json" \+ -d '{+ "url": "https://www.artificialintelligence-news.com/",+ "query": "Latest AI News",+ "depth": 2+ }'+```+</RequestExample>++## Use Cases++- **Content Research**: Extract specific information from research papers, blogs, or news articles+- **Price Monitoring**: Get pricing information from e-commerce sites+- **Data Extraction**: Pull structured data from specific web pages+- **Content Analysis**: Analyze and summarize content from target websites++## Pricing++**Cost per request**: `1 cent Γ depth`++Examples:+- depth=2 = 2 cents per request (default value)+- depth=3 = 3 cents per request+- depth=4 = 4 cents per request+- depth=5 = 5 cents per requestdiff --git a/docs/api-reference/simple-search.mdx b/docs/api-reference/simple-search.mdxnew file mode 100644index 000000000..f25cafafe--- /dev/null+++ b/docs/api-reference/simple-search.mdx@@ -0,0 +1,128 @@+---+title: "Simple Search"+api: "POST https://api.browser-use.com/api/v1/simple-search"+description: "Search Google and extract relevant content from multiple top results"+---++## Overview++The Simple Search endpoint processes your search query and extracts relevant content from multiple top results using AI. This is perfect for research, content aggregation, or finding specific information across multiple websites.++π‘ **Complete working example**: [simple_search.py](https://github.com/browser-use/browser-use/blob/main/examples/search/simple_search.py)++## Request++<ParamField body="query" type="string" required>+ The search query to process+</ParamField>++<ParamField body="max_websites" type="integer" default="5">+ Maximum number of websites to process from search results (1-10)+</ParamField>++<ParamField body="depth" type="integer" default="2">+ How deep to navigate within each website (2-5)+</ParamField>++## Response++<ResponseField name="results" type="array">+ Array of results from processed websites++ <Expandable title="result object">+ <ResponseField name="url" type="string">+ The URL of the processed website+ </ResponseField>++ <ResponseField name="content" type="string">+ Extracted content relevant to the search query+ </ResponseField>+ </Expandable>+</ResponseField>++<ResponseExample>+```json Response+{+ "results": [+ {+ "url": "https://example1.com",+ "content": "Relevant content extracted from the first website..."+ },+ {+ "url": "https://example2.com",+ "content": "Relevant content extracted from the second website..."+ }+ ]+}+```+</ResponseExample>++## Example++<RequestExample>+```python Python+import aiohttp+import asyncio++async def search():+ payload = {+ "query": "latest developments in artificial intelligence",+ "max_websites": 5,+ "depth": 2+ }++ headers = {+ "Authorization": "Bearer YOUR_API_KEY",+ "Content-Type": "application/json"+ }++ async with aiohttp.ClientSession() as session:+ async with session.post(+ "https://api.browser-use.com/api/v1/simple-search",+ json=payload,+ headers=headers+ ) as response:+ return await response.json()++result = asyncio.run(search())+print(result)+```++```javascript JavaScript+const response = await fetch('https://api.browser-use.com/api/v1/simple-search', {+ method: 'POST',+ headers: {+ 'Authorization': 'Bearer YOUR_API_KEY',+ 'Content-Type': 'application/json'+ },+ body: JSON.stringify({+ query: 'latest developments in artificial intelligence',+ max_websites: 5,+ depth: 2+ })+});++const result = await response.json();+console.log(result);+```++```bash cURL+curl -X POST "https://api.browser-use.com/api/v1/simple-search" \+ -H "Authorization: Bearer YOUR_API_KEY" \+ -H "Content-Type: application/json" \+ -d '{+ "query": "latest developments in artificial intelligence",+ "max_websites": 5,+ "depth": 2+ }'+```+</RequestExample>++## Pricing++**Cost per request**: `1 cent Γ depth Γ max_websites`++Examples:+- depth=2, max_websites=5 = 10 cents per request (default values)+- depth=2, max_websites=3 = 6 cents per request+- depth=3, max_websites=2 = 6 cents per requestdiff --git a/docs/cloud/search.mdx b/docs/cloud/search.mdxnew file mode 100644index 000000000..8ce7ac179--- /dev/null+++ b/docs/cloud/search.mdx@@ -0,0 +1,88 @@+---+title: "Search API Quickstart"+description: "Get started with Browser Use's search endpoints to extract content from websites"+---++## Quick Start++The Search API allows you to quickly extract relevant content from websites using AI. There are two main endpoints:++π‘ **Complete working examples** are available in the [examples/search](https://github.com/browser-use/browser-use/tree/main/examples/search) folder.++### Simple Search+Search Google and extract content from multiple top results:++```python+import aiohttp+import asyncio++async def simple_search():+ payload = {+ "query": "latest AI news",+ "max_websites": 5,+ "depth": 2+ }++ headers = {+ "Authorization": "Bearer YOUR_API_KEY",+ "Content-Type": "application/json"+ }++ async with aiohttp.ClientSession() as session:+ async with session.post(+ "https://api.browser-use.com/api/v1/simple-search",+ json=payload,+ headers=headers+ ) as response:+ result = await response.json()+ return result++asyncio.run(simple_search())+```++### Search URL+Extract content from a specific URL:++```python+async def search_url():+ payload = {+ "url": "https://browser-use.com/#pricing",+ "query": "Find pricing information for Browser Use",+ "depth": 2+ }++ headers = {+ "Authorization": "Bearer YOUR_API_KEY",+ "Content-Type": "application/json"+ }++ async with aiohttp.ClientSession() as session:+ async with session.post(+ "https://api.browser-use.com/api/v1/search-url",+ json=payload,+ headers=headers+ ) as response:+ result = await response.json()+ return result++asyncio.run(search_url())+```++## Parameters++- **query**: Search query or content to extract+- **depth**: How deep to navigate (2-5, default: 2)+- **max_websites**: Number of websites to process (simple-search only, default: 5)+- **url**: Target URL to extract from (search-url only)++## Pricing++### Simple Search+**Cost per request**: `1 cent Γ depth Γ max_websites`++Example: depth=2, max_websites=3 = 6 cents per request++### Search URL+**Cost per request**: `1 cent Γ depth`++Example: depth=2 = 2 cents per requestdiff --git a/docs/docs.json b/docs/docs.jsonindex 2b7876547..0b259b393 100644--- a/docs/docs.json+++ b/docs/docs.json@@ -58,11 +58,19 @@"group": "Cloud API v1","pages": ["cloud/quickstart",+ "cloud/search","cloud/implementation","cloud/webhooks","cloud/authentication"]},+ {+ "group": "Search API",+ "pages": [+ "api-reference/simple-search",+ "api-reference/search-url"+ ]+ },{"group": "Tasks API","pages": [diff --git a/examples/search/search_url.py b/examples/search/search_url.pynew file mode 100644index 000000000..2eb3687ab--- /dev/null+++ b/examples/search/search_url.py@@ -0,0 +1,65 @@+"""+Search URL API Example++This example shows how to use the Browser Use API to extract specific+content from a given URL based on your query.++Usage:+ # Copy this function and customize the parameters+ result = await search_url("https://example.com", "what to find", depth=2)+"""++import asyncio+import os++import aiohttp+from dotenv import load_dotenv++# Load environment variables+load_dotenv()+++async def search_url(url: str, query: str, depth: int = 2):+ payload = {'url': url, 'query': query, 'depth': depth}++ headers = {'Authorization': f'Bearer {os.getenv("BROWSER_USE_API_KEY")}', 'Content-Type': 'application/json'}++ print('Testing Search URL API...')+ print(f'URL: {url}')+ print(f'Query: {query}')+ print(f'Depth: {depth}')+ print('-' * 50)++ try:+ async with aiohttp.ClientSession() as session:+ async with session.post(+ 'https://api.browser-use.com/api/v1/search-url',+ json=payload,+ headers=headers,+ timeout=aiohttp.ClientTimeout(total=300),+ ) as response:+ if response.status == 200:+ result = await response.json()+ print('β Success!')+ print(f'URL processed: {result.get("url", "N/A")}')+ content = result.get('content', '')+ print(f'Content: {content}')+ return result+ else:+ error_text = await response.text()+ print(f'β Error {response.status}: {error_text}')+ return None+ except Exception as e:+ print(f'β Exception: {str(e)}')+ return None+++if __name__ == '__main__':+ # Example 1: Extract pricing info+ asyncio.run(search_url('https://browser-use.com/#pricing', 'Find pricing information for Browser Use'))++ # Example 2: News article analysis+ # asyncio.run(search_url("https://techcrunch.com", "latest startup funding news", depth=3))++ # Example 3: Product research+ # asyncio.run(search_url("https://github.com/browser-use/browser-use", "installation instructions", depth=2))diff --git a/examples/search/simple_search.py b/examples/search/simple_search.pynew file mode 100644index 000000000..487429ab8--- /dev/null+++ b/examples/search/simple_search.py@@ -0,0 +1,67 @@+"""+Simple Search API Example++This example shows how to use the Browser Use API to search and extract+content from multiple websites based on a query.++Usage:+ # Copy this function and customize the parameters+ result = await simple_search("your search query", max_websites=5, depth=2)+"""++import asyncio+import os++import aiohttp+from dotenv import load_dotenv++# Load environment variables+load_dotenv()+++async def simple_search(query: str, max_websites: int = 5, depth: int = 2):+ payload = {'query': query, 'max_websites': max_websites, 'depth': depth}++ headers = {'Authorization': f'Bearer {os.getenv("BROWSER_USE_API_KEY")}', 'Content-Type': 'application/json'}++ print('Testing Simple Search API...')+ print(f'Query: {query}')+ print(f'Max websites: {max_websites}')+ print(f'Depth: {depth}')+ print('-' * 50)++ try:+ async with aiohttp.ClientSession() as session:+ async with session.post(+ 'https://api.browser-use.com/api/v1/simple-search',+ json=payload,+ headers=headers,+ timeout=aiohttp.ClientTimeout(total=300),+ ) as response:+ if response.status == 200:+ result = await response.json()+ print('β Success!')+ print(f'Results: {len(result.get("results", []))} websites processed')+ for i, item in enumerate(result.get('results', [])[:2], 1):+ print(f'\n{i}. {item.get("url", "N/A")}')+ content = item.get('content', '')+ print(f' Content: {content}')+ return result+ else:+ error_text = await response.text()+ print(f'β Error {response.status}: {error_text}')+ return None+ except Exception as e:+ print(f'β Exception: {str(e)}')+ return None+++if __name__ == '__main__':+ # Example 1: Basic search+ asyncio.run(simple_search('latest AI news'))++ # Example 2: Custom parameters+ # asyncio.run(simple_search("python web scraping", max_websites=3, depth=3))++ # Example 3: Research query+ # asyncio.run(simple_search("climate change solutions 2024", max_websites=7, depth=2))