File tree Expand file tree Collapse file tree 1 file changed +29
-9
lines changed Expand file tree Collapse file tree 1 file changed +29
-9
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,26 @@ main().catch((err) => {
9595
9696<Tab title = " Python" >
9797
98+ <Tip >
99+ For uv installation instructions see the [ uv installation guide] ( https://docs.astral.sh/uv/getting-started/installation/#__tabbed_1_1 ) .
100+ </Tip >
101+
102+ ### Initialize virtual environment
103+
104+ <CodeGroup >
105+
106+ ``` bash uv
107+ uv init my-stagehand-project
108+ cd my-stagehand-project
109+ ```
110+
111+ ``` bash pip
112+ python -m venv venv
113+ source venv/bin/activate # On Windows: venv\Scripts\activate
114+ ```
115+
116+ </CodeGroup >
117+
98118### Add dependencies
99119
100120<CodeGroup >
@@ -128,6 +148,10 @@ BROWSERBASE_PROJECT_ID=your_project_id
128148import os
129149import asyncio
130150from stagehand import Stagehand
151+ from pydantic import BaseModel
152+
153+ class PageData (BaseModel ):
154+ title: str
131155
132156async def main ():
133157 stagehand = Stagehand(
@@ -143,16 +167,12 @@ async def main():
143167 await page.act(" Click the sign in button" )
144168
145169 # Extract structured data
146- result = await page.extract({
147- " instruction" : " extract the page title" ,
148- " schema" : {
149- " title" : {
150- " type" : " string"
151- }
152- }
153- })
170+ result = await page.extract(
171+ instruction = " extract the page title" ,
172+ schema = PageData
173+ )
154174
155- print (result[ " title" ] )
175+ print (result. title)
156176 await stagehand.close()
157177
158178if __name__ == " __main__" :
You can’t perform that action at this time.
0 commit comments