> For the complete documentation index, see [llms.txt](https://wwydev.gitbook.io/crawlist-zh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wwydev.gitbook.io/crawlist-zh/zhi-nan/script.md).

# 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>" %}
