指令列表

通用参数

下面定义的所有指令都有一致的参数集。参数如下:

type

  • 类型: Enum["click", "input", "scroll", "scroll_to_bottom", "wait", "wait_for_element", "fetch_resource"]

  • 描述: 浏览器指令类型

timeout_s

  • 类型: int

  • 描述: 最多等待多少秒直到操作执行终止。

  • 限制: 0 < timeout_s <= 60

  • 默认值: 5

wait_time_s

  • 类型: int

  • 描述: 显式使用多少秒执行操作。

  • 限制: 0 < wait_time_s <= 60

  • 默认值: 0

on_error

  • 类型: Enum["error", "skip"]

  • 描述: 如果此指令失败,指示要对指令执行的操作。

    • "error": 停止执行浏览器指令。

    • "skip": 继续下一条指令。

  • 默认值: "error"

Instructions

click

  • 描述: Clicks an element and wait a set count of seconds.

  • 参数:

    • type: str = "click"

    • selector: dict

      • type: Enum["xpath", "css", "text"]

      • value: str

  • 示例:

{
    "type": "click",
    "selector": {
        "type": "xpath",
        "value": "//button"
    }
}

input

  • 描述: 在所选元素中输入文本。

  • 参数:

    • type: str = "input"

    • selector: dict

      • type: Enum["xpath", "css", "text"]

      • value: str

    • value: str

    • 示例:

{
    "type": "input",
    "selector": {
        "type": "xpath",
        "value": "//input"
    },
    "value": "pizza boxes"
}

scroll

  • 描述: 滚动一定数量的像素。

  • 参数:

    • type: str = "scroll"

    • x: int

    • y: int

  • 示例:

{
    "type": "scroll",
    "x": 0,
    "y": 100
}

scroll_to_bottom

  • 描述: 以一定数量的秒数滚动到底部。

  • 参数:

    • type: str = "scroll_to_bottom"

  • 示例:

{
    "type": "scroll_to_bottom",
    "timeout_s": 10
}

wait

  • 描述: 等待一定数量的秒数。

  • 参数:

    • type: str = "wait"

  • 示例:

{
    "type": "wait",
    "wait_time_s": 2
}

wait_for_element

  • 描述: 等待以一定数量的秒数加载元素。

  • 参数:

    • type: str = "wait_for_element"

    • selector: dict

      • type: Enum["xpath", "css", "text"]

      • value: str

    • 示例:

{
    "type": "wait_for_element",
    "selector": {
        "type": "text",
        "value": "Load More Items"
    },
    "timeout_s": 5
}

fetch_resource

fetch_resource指令不能与其余指令组合使用。

  • 描述: 获取与设置模式匹配的第一个Fetch/XHR资源的首次出现。

  • 参数:

    • type: str = "fetch_resource"

    • filter: str(RegEx expression)

    • on_error: Enum["error", "skip"]

  • 示例:

{
    "type": "fetch_resource",
    "filter": "/graphql/item/"
}

指令验证

有关指令格式的任何不一致都将导致400状态代码和相应的错误消息。

例如,如下载荷:

{
    "source": "universal",
    "url": "https://www.example.com/",
    "render": "html",
    "browser_instructions": [
        {
            "type": "unsupported-wait",
            "wait_time_s": 5
        }
    ]
}

将导致:

{    
    "errors": {
        "message": "Unsupported action type `unsupported-wait`, choose from 'click,fetch_resource,input,scroll,scroll_to_bottom,wait,wait_for_element'"
    }
}

最后更新于