Action

Crawlipt includes some built-in actions for better interaction with web pages. At the same time, you can also add your own action methods for expansion.

Built-in action methods

All script methods (or aliases) are automatically mapped to the execution function, and all parameters correspond one-to-one. All WebElement elements are located through xpath.

Add your own action

Before adding your own action method, it is recommended that you first learn the basic usage of selenium

Refer to the following example to add your own action

import crawlipt as cpt
from selenium.webdriver.remote.webdriver import WebDriver
"""
(1) Must be a callable function or static method within a class
(2) The check annotation must be used to exclude the syntax check of the driver, otherwise an exception will be thrown during the syntax check phase
(3) All parameters must indicate the type, otherwise they cannot pass the syntax check
(4) All parameters must be of the underlying type in Python
(5) The function return value must be specified. If there is no return value, return None (->None)
(6) Driver is a fixed variable, which means it must include the parameter (driver: WebDriver)
(7) The parameters of the action method cannot contain keywords such as if, check, loop, etc., otherwise they will not take effect
"""
@cpt.check(exclude="driver")  
def myAction(driver: WebDriver, **args) -> None:
    """
    your doc
    :param driver: selenium webdriver
    :param **args: your args
    """
    # write your code


# Add the script as follows
cpt.Script.add_action(myAction)

Last updated