2
2
3
3
This tool is a wrapper around the Playwright library. It allows you to navigate to a website, extract text and hyperlinks, and click on elements.
4
4
5
+ > ** Warning**
6
+ > Only support async functions and playwright browser APIs.
7
+
5
8
## Installation
6
9
7
10
```
@@ -10,55 +13,65 @@ pip install llama-index-tools-playwright
10
13
11
14
## Setup
12
15
13
- In order to use this tool, you need to have a sync Playwright browser instance. You can hook one up by running the following code:
16
+ In order to use this tool, you need to have a async Playwright browser instance. You can hook one up by running the following code:
14
17
15
18
``` python
16
- browser = PlaywrightToolSpec.create_sync_playwright_browser (headless = False )
17
- playwright_tool = PlaywrightToolSpec.from_sync_browser (browser)
19
+ browser = PlaywrightToolSpec.create_async_playwright_browser (headless = False )
20
+ playwright_tool = PlaywrightToolSpec.from_async_browser (browser)
18
21
```
19
22
20
23
## Usage
21
24
22
25
### Navigate to a website
23
26
24
27
``` python
25
- playwright_tool.navigate_to(" https://playwright.dev/python/docs/intro" )
28
+ await playwright_tool.navigate_to(" https://playwright.dev/python/docs/intro" )
29
+ ```
30
+
31
+ ### Navigate back
32
+
33
+ ``` python
34
+ await playwright_tool.navigate_back()
26
35
```
27
36
28
37
### Get current page URL
29
38
30
39
``` python
31
- playwright_tool.get_current_page()
40
+ await playwright_tool.get_current_page()
32
41
```
33
42
34
43
### Extract all hyperlinks
35
44
36
45
``` python
37
- playwright_tool.extract_hyperlinks()
46
+ await playwright_tool.extract_hyperlinks()
38
47
```
39
48
40
49
### Extract all text
41
50
42
51
``` python
43
- playwright_tool.extract_text()
52
+ await playwright_tool.extract_text()
44
53
```
45
54
46
55
### Get element attributes
47
56
48
57
``` python
49
- element = playwright_tool.get_elements(
58
+ element = await playwright_tool.get_elements(
50
59
selector = " ELEMENT_SELECTOR" , attributes = [" innerText" ]
51
60
)
52
61
```
53
62
54
63
### Click on an element
55
64
56
65
``` python
57
- playwright_tool.click(selector = " ELEMENT_SELECTOR" )
66
+ await playwright_tool.click(selector = " ELEMENT_SELECTOR" )
58
67
```
59
68
60
69
### Fill in an input field
61
70
62
71
``` python
63
- playwright_tool.fill(selector = " ELEMENT_SELECTOR" , value = " Hello" )
72
+ await playwright_tool.fill(selector = " ELEMENT_SELECTOR" , value = " Hello" )
64
73
```
74
+
75
+ ## Agentic Usage
76
+
77
+ This tool has a more extensive example usage documented in a Jupyter notebook [ here] ( https://github.com/run-llama/llama_index/blob/main/llama-index-integrations/tools/llama-index-tools-playwright/examples/playwright_browser_agent.ipynb )
0 commit comments