Skip to content

Commit 13e5ae4

Browse files
update readme
1 parent b3cf95b commit 13e5ae4

File tree

1 file changed

+21
-37
lines changed

1 file changed

+21
-37
lines changed

README.md

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@
3535
</a>
3636
</p>
3737

38-
39-
> This is a Python SDK for Stagehand. We also have a TypeScript SDK available <a href="https://github.com/browserbase/stagehand" >here</a>.
40-
41-
4238
> Stagehand Python SDK is currently available as an early release, and we're actively seeking feedback from the community. Please join our [Slack community](https://stagehand.dev/slack) to stay updated on the latest developments and provide feedback.
4339
40+
> We also have a TypeScript SDK available <a href="https://github.com/browserbase/stagehand" >here</a>.
41+
4442
## Why Stagehand?
4543

4644
*Stagehand is the easiest way to build browser automations with AI-powered interactions.*
@@ -55,7 +53,7 @@ Most existing browser automation tools either require you to write low-level cod
5553

5654
-----
5755

58-
### TL;DR Automate the web *reliably* with natural language:
56+
### TL;DR: Automate the web *reliably* with natural language:
5957

6058
- **act** — Instruct the AI to perform actions (e.g. click a button or scroll).
6159
```python
@@ -89,27 +87,26 @@ from dotenv import load_dotenv
8987
from pydantic import BaseModel, Field, HttpUrl
9088

9189
from stagehand import StagehandConfig, Stagehand
92-
from stagehand.types import ExtractOptions
90+
from stagehand.schemas import ExtractOptions
9391

9492
# Load environment variables
9593
load_dotenv()
9694

9795
# Define Pydantic models for structured data extraction
9896
class Company(BaseModel):
99-
name: str = Field(..., description="The name of the company")
100-
url: HttpUrl = Field(..., description="The URL of the company website or relevant page")
101-
102-
class Companies(BaseModel):
103-
companies: list[Company] = Field(..., description="List of companies extracted from the page, maximum of 5 companies")
97+
name: str = Field(..., description="Company name")
98+
url: HttpUrl = Field(..., description="Company URL")
10499

100+
class Companies(BaseModel):
101+
companies: list[Company] = Field(..., description="List of companies")
102+
105103
async def main():
106104
# Create configuration
107105
config = StagehandConfig(
108106
api_key=os.getenv("BROWSERBASE_API_KEY"),
109107
project_id=os.getenv("BROWSERBASE_PROJECT_ID"),
110108
model_name="gpt-4o",
111109
model_client_options={"apiKey": os.getenv("MODEL_API_KEY")},
112-
verbose=1,
113110
)
114111

115112
# Initialize async client
@@ -122,44 +119,31 @@ async def main():
122119
try:
123120
# Initialize the client
124121
await stagehand.init()
125-
print("✓ Successfully initialized Stagehand async client")
126-
127-
# Navigate to AIgrant
128-
await stagehand.page.goto("https://www.aigrant.com")
129-
print("✓ Navigated to AIgrant")
130-
131-
# Click the "Get Started" button using AI
132-
await stagehand.page.act("click the button with text 'Get Started'")
133-
print("✓ Clicked 'Get Started' button")
134-
135-
# Observe elements on the page
136-
observed = await stagehand.page.observe("the button with text 'Get Started'")
137-
print("✓ Observed 'Get Started' button")
122+
page = stagehand.page
123+
124+
await page.goto("https://www.aigrant.com")
138125

139126
# Extract companies using structured schema
140127
extract_options = ExtractOptions(
141-
instruction="Extract the names and URLs of up to 5 companies mentioned on this page",
142-
schema_definition=Companies.model_json_schema()
128+
instruction="Extract names and URLs of up to 5 companies in batch 3",
129+
schema_definition=Companies
143130
)
144131

145-
companies_data = await stagehand.page.extract(extract_options)
146-
print("✓ Extracted companies data")
132+
companies_data = await page.extract(extract_options)
147133

148134
# Display results
149-
print("\nExtracted Companies:")
150-
if hasattr(companies_data, "companies"):
151-
for idx, company in enumerate(companies_data.companies, 1):
152-
print(f"{idx}. {company.name}: {company.url}")
153-
else:
154-
print("No companies were found in the extraction result")
135+
print("Extracted Companies:")
136+
for idx, company in enumerate(companies_data.companies, 1):
137+
print(f"{idx}. {company.name}: {company.url}")
138+
139+
await page.act("click the link to the company Browserbase")
155140

156141
except Exception as e:
157-
print(f"Error during testing: {str(e)}")
142+
print(f"Error: {str(e)}")
158143
raise
159144
finally:
160145
# Close the client
161146
await stagehand.close()
162-
print("Stagehand async client closed")
163147

164148
if __name__ == "__main__":
165149
asyncio.run(main())

0 commit comments

Comments
 (0)