Loop

Crawlipt provides the "loop" keyword for looping

'loop' keyword

When a layer contains the loop keyword, the script will directly enter the script within the loop and loop based on the while or cnt conditions. After the loop terminates, it will skip the current layer and enter the next layer to execute the action method of the next layer.

loop condition

The loop keyword has two conditions: 'while' and 'cnt'. The while condition can be evaluated in conjunction with the condition method. If the condition method is false, the loop is terminated. The 'cnt' condition is a counter, which means the script will loop 'cnt' times. If both condition and cnt conditions occur simultaneously, both conditions need to be met before the loop can continue.

loop script

The loop script needs to be passed in using script keywords within the loop, supporting JSON, dict, and list types

loop example

Note: Loop can be nested multiple times

step = [{
    "method": "redirect",
    "url": "https://www.bchrt.com/tools/click-counter/",
}, {
    "loop": {
        "while": {
            "condition": "checkNum",
            "xpath": "//*[@id=\"count\"]"
        },
        "script": [{
            "loop": {
                "cnt": 5,
                "script": {
                    "method": "click",
                    "xpath": "//*[@id=\"addbtn\"]",
                },
            }
        },
            {
                "method": "click",
                "xpath": "//*[@id=\"subbtn\"]",
            }
        ]
    }
}, {
    "method": "getAttribute",
    "xpath": "//*[@id=\"count\"]",
    "name": "value"
}]

Last updated