# Script

### Script 定义

该脚本是一个JSON字符串。JSON可以用大多数语言进行解析，使其更加通用。嵌套多个JSON以实现连续操作。

#### 样例

```json
 {
	"method": "redirect",
	"url": "https://www.baidu.com/",
	"next": {
		"method": "inputKeyword",
		"xpath": "//*[@id=\"kw\"]",
		"keyword": "和泉雾纱",
		"next": {
			"method": "click",
			"xpath": "//*[@id=\"su\"]"
		}
	}
}
```

方法及其参数对应于所有[action](/crawlist-zh/zhi-nan/action.md#parms-of-action)名称及其参数

### 使用

更建议您在[pre\_load](/crawlist-zh/zhi-nan/action.md#what-is-pre_load)中使用脚本。

```python
import crawlist as cl

class MyPager(cl.DynamicNumButtonPager):
    def pre_load(self, webdriver: WebDriver) -> None:
        script = {
            "method": "redirect",
            "url": "https://www.baidu.com/",
            "next": {
                "method": "inputKeyword",
                "xpath": "//*[@id=\"kw\"]",
                "keyword": "和泉雾纱",
                "next": {
                    "method": "click",
                    "xpath": "//*[@id=\"su\"]"
                }
            }
        }
        cl.Script(script)(webdriver)
```

### crawlipt

如果您想要更丰富的脚本，可以使用crawlipt项目

```sh
pip install crawlipt
```

{% embed url="<https://github.com/WwwwwyDev/crawlipt>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wwydev.gitbook.io/crawlist-zh/zhi-nan/script.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
