Script

By using built-in scripts, you can better operate selenium's webdriver. It can also facilitate you to store scripts in physical storage such as databases, so that you can adjust them faster.

Script Definition

The script is a JSON. JSON can be parsed in most languages, making it more versatile. Nesting multiple JSONs to achieve continuous operations.

Example

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

Method and its parameters correspond to all action method names and their parameters

Use the script

It is more recommended that you use scripts for pre_load.

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

If you want a richer script, you can use the crawlipt project

pip install crawlipt

Last updated