@@ -36,6 +36,8 @@ Here is how an `extract` call might look for a single object:
36
36
37
37
<CodeGroup >
38
38
``` typescript TypeScript
39
+ import { z } from ' zod/v3' ;
40
+
39
41
const item = await page .extract ({
40
42
instruction: " extract the price of the item" ,
41
43
schema: z .object ({
@@ -45,6 +47,8 @@ const item = await page.extract({
45
47
```
46
48
47
49
``` python Python
50
+ from pydantic import BaseModel
51
+
48
52
class Extraction (BaseModel ):
49
53
price: float
50
54
@@ -66,6 +70,8 @@ Here is how an `extract` call might look for a list of objects.
66
70
67
71
<CodeGroup >
68
72
``` typescript TypeScript
73
+ import { z } from ' zod/v3' ;
74
+
69
75
const apartments = await page .extract ({
70
76
instruction:
71
77
" Extract ALL the apartment listings and their details, including address, price, and square feet." ,
@@ -84,6 +90,8 @@ console.log("the apartment list is: ", apartments);
84
90
```
85
91
86
92
``` python Python
93
+ from pydantic import BaseModel
94
+
87
95
class Apartment (BaseModel ):
88
96
address: str
89
97
price: str
@@ -180,6 +188,8 @@ You can provide additional context to your schema to help the model extract the
180
188
181
189
<CodeGroup >
182
190
``` typescript TypeScript
191
+ import { z } from ' zod/v3' ;
192
+
183
193
const apartments = await page .extract ({
184
194
instruction:
185
195
" Extract ALL the apartment listings and their details, including address, price, and square feet." ,
@@ -196,6 +206,8 @@ const apartments = await page.extract({
196
206
```
197
207
198
208
``` python Python
209
+ from pydantic import BaseModel, Field
210
+
199
211
class Apartment (BaseModel ):
200
212
address: str = Field(... , description = " the address of the apartment" )
201
213
price: str = Field(... , description = " the price of the apartment" )
@@ -221,6 +233,8 @@ Here is how an `extract` call might look for extracting a link or URL. This also
221
233
222
234
<CodeGroup >
223
235
``` typescript TypeScript
236
+ import { z } from ' zod/v3' ;
237
+
224
238
const extraction = await page .extract ({
225
239
instruction: " extract the link to the 'contact us' page" ,
226
240
schema: z .object ({
@@ -232,6 +246,8 @@ console.log("the link to the contact us page is: ", extraction.link);
232
246
```
233
247
234
248
``` python Python
249
+ from pydantic import BaseModel, HttpUrl
250
+
235
251
class Extraction (BaseModel ):
236
252
link: HttpUrl # note the usage of HttpUrl here
237
253
@@ -414,4 +430,4 @@ for page_num in page_numbers:
414
430
<Card title = " Observe" icon = " magnifying-glass" href = " /basics/observe" >
415
431
Analyze pages with observe()
416
432
</Card >
417
- </CardGroup >
433
+ </CardGroup >
0 commit comments