Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion docs/basics/extract.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Here is how an `extract` call might look for a single object:

<CodeGroup>
```typescript TypeScript
import { z } from 'zod/v3';

const item = await page.extract({
instruction: "extract the price of the item",
schema: z.object({
Expand All @@ -45,6 +47,8 @@ const item = await page.extract({
```

```python Python
from pydantic import BaseModel

class Extraction(BaseModel):
price: float

Expand All @@ -66,6 +70,8 @@ Here is how an `extract` call might look for a list of objects.

<CodeGroup>
```typescript TypeScript
import { z } from 'zod/v3';

const apartments = await page.extract({
instruction:
"Extract ALL the apartment listings and their details, including address, price, and square feet.",
Expand All @@ -84,6 +90,8 @@ console.log("the apartment list is: ", apartments);
```

```python Python
from pydantic import BaseModel

class Apartment(BaseModel):
address: str
price: str
Expand Down Expand Up @@ -180,6 +188,8 @@ You can provide additional context to your schema to help the model extract the

<CodeGroup>
```typescript TypeScript
import { z } from 'zod/v3';

const apartments = await page.extract({
instruction:
"Extract ALL the apartment listings and their details, including address, price, and square feet.",
Expand All @@ -196,6 +206,8 @@ const apartments = await page.extract({
```

```python Python
from pydantic import BaseModel, Field

class Apartment(BaseModel):
address: str = Field(..., description="the address of the apartment")
price: str = Field(..., description="the price of the apartment")
Expand All @@ -221,6 +233,8 @@ Here is how an `extract` call might look for extracting a link or URL. This also

<CodeGroup>
```typescript TypeScript
import { z } from 'zod/v3';

const extraction = await page.extract({
instruction: "extract the link to the 'contact us' page",
schema: z.object({
Expand All @@ -232,6 +246,8 @@ console.log("the link to the contact us page is: ", extraction.link);
```

```python Python
from pydantic import BaseModel, HttpUrl

class Extraction(BaseModel):
link: HttpUrl # note the usage of HttpUrl here

Expand Down Expand Up @@ -414,4 +430,4 @@ for page_num in page_numbers:
<Card title="Observe" icon="magnifying-glass" href="/basics/observe">
Analyze pages with observe()
</Card>
</CardGroup>
</CardGroup>