You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# why
its about time!
# what changed
added python docs to mintlify
# test plan
n/a
---------
Co-authored-by: Kylejeong2 <[email protected]>
Co-authored-by: miguel <[email protected]>
Copy file name to clipboardExpand all lines: docs/concepts/act.mdx
+53-12Lines changed: 53 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,58 +11,91 @@ Stagehand has an `act()` function that can be used to execute actions on a page
11
11

12
12
13
13
This workflow is as simple as the following lines of code:
14
-
```js
14
+
15
+
<CodeGroup>
16
+
```typescript TypeScript
15
17
const page =stagehand.page
16
18
// Navigate to the URL
17
19
awaitpage.goto("https://linkedin.com");
18
-
20
+
// Click on jobs menu selection
19
21
awaitpage.act("click 'jobs'");
22
+
// Click on first posting
20
23
awaitpage.act("click the first job posting");
21
24
```
25
+
```python Python
26
+
page = stagehand.page
27
+
# Navigate to the URL
28
+
await page.goto("https://linkedin.com")
29
+
# Click on jobs menu selection
30
+
await page.act("click 'jobs'")
31
+
# Click on first posting
32
+
await page.act("click the first job posting")
33
+
```
34
+
</CodeGroup>
22
35
23
36
The `page` object extends the Playwright page object, so you can use any of the [Playwright page methods](https://playwright.dev/docs/api/class-page) with it.
24
37
25
-
## Read structured data from the page
38
+
## Get structured data from the page
26
39
27
-
You can use the `extract()` method to extract structured data from the page. Here's an example of how to extract the job title from the job posting:
40
+
You can use `extract()` to get structured data from the page.
41
+
Here's an example of how to extract the job title from the job posting:
28
42
29
-
```js
43
+
<CodeGroup>
44
+
```typescript TypeScript
30
45
const { jobTitle } =awaitpage.extract({
31
46
instruction: "Extract the job title from the job posting",
32
47
schema: z.object({
33
48
jobTitle: z.string(),
34
49
}),
35
50
});
36
51
```
52
+
```python Python
53
+
result =await page.extract("Extract the job title from the job posting")
54
+
```
55
+
</CodeGroup>
37
56
38
-
Stagehand uses [Zod](https://zod.dev/) to help you define the schema of the data to be extracted.
57
+
<Info>
58
+
Stagehand uses [Zod](https://zod.dev/) for TypeScript and [Pydantic](https://docs.pydantic.dev/) for Python to help you define the schema of the data to be extracted.
59
+
</Info>
39
60
40
61
## Preview/Cache an action
41
62
42
63
Sometimes you want to preview an action before it's executed. You can do this by calling `page.observe()` before `act()`.
Stagehand gives AI agents powerful tools to control a browser completely autonomously. Watch below as a Stagehand agent autonomously navigates to a URL, takes actions on the page, and extracts structured data to answer a question.
13
9
There's quite a few ways to build an agent with Stagehand. Let's look at a few of them.
14
10
@@ -20,8 +16,8 @@ The above example is a Claude agent that uses Stagehand to control a browser. At
20
16
This means Claude is intelligent enough to know when to request a browser screenshot, and it can then use that screenshot to make decisions about what actions to take next.
0 commit comments