> For the complete documentation index, see [llms.txt](https://developers.oxylabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.oxylabs.io/products/cn/web-scraper-api/features/custom-parser/writing-instructions-manually/list-of-functions.md).

# 解析函数列表

了解自定义解析器支持的完整函数列表：正则表达式、XPath、CSS 等。

您可以在以下页面中找到每个函数的使用示例： [解析函数示例](/products/cn/web-scraper-api/features/custom-parser/writing-instructions-manually/list-of-functions/function-examples.md) 页面。

## 如何传递参数

每个函数通过以下方式接收其设置： `_args`。使用两种形状，它们不可互换：

| 形状                   | 函数                                                                                          | 示例                            |
| -------------------- | ------------------------------------------------------------------------------------------- | ----------------------------- |
| **数组** - 方括号中的一个或多个值 | `xpath`, `xpath_one`, `css`, `css_one`, `regex_find_all`, `regex_search`, `regex_substring` | `"_args": ["//h4/text()"]`    |
| **单个值** - 无方括号       | `join`, `select_nth`                                                                        | `"_args": 0` · `"_args": " "` |

对于 selector 和 RegEx 函数，数组还允许你列出备用表达式：当前一个没有找到结果时，会尝试下一个。没有设置项的函数（`element_text`, `amount_from_string`, `length`, `最大`，……）不需要任何 `_args` 设置。

使用错误的形状不会导致任务失败：该字段会返回 `null`, `parse_status_code` is `12005`，以及 `_warnings` 包含 *收到无效类型的参数 `数组`* （或 `字符串`).

## HTML 处理

### `element_text`

* **名称**: `element_text`
* **说明**：从 `html`中提取文本。去除首尾空白字符。
* **参数**：不适用
* **有效输入类型：** `html`
* **预期输出类型：** `字符串`

### `xpath`

* **名称**: `xpath`
* **说明**：在给定的输入值上执行 XPath 表达式。如果执行失败且未产生结果，则使用数组中的下一个表达式。表达式中可以使用 XSLT 函数。支持 XPath 1.0。支持 XSLT 1.0。
* **参数**:
  * `xpath_expressions`
    * **类型**: `[字符串]`
    * **必需**: `true`
* **有效输入类型：**
  * `html`
* **预期输出类型：**
  * `[字符串]`
  * `[HTML]`
  * `字符串`
  * `浮点数`
  * `布尔值`

### `xpath_one`

* **名称**: `xpath_one`
* **说明**：与 `xpath`的工作方式相同，但即使提供的 XPath 选择了多个值，也只返回第一个值。
* **参数**:
  * `xpath_expressions`
    * **类型**: `[字符串]`
    * **必需**: `true`
* **有效输入类型：**
  * `html`
* **预期输出类型：**
  * `字符串`
  * `html`
  * `字符串`
  * `浮点数`
  * `布尔值`

### `css`

* **名称**: `css`
* **说明**：在给定的输入值上执行 CSS 表达式。如果执行失败且未产生结果，则使用数组中的下一个表达式。 **请注意，以下函数的输出 `css` 函数的输出始终是一个包含 HTML 元素的 JSON 数组（包括开始和结束标签）。如果你想提取元素内容，可以随后执行 `element_text` 函数。**
* **参数**:
  * `css_expressions`
    * **类型**: `[字符串]`
    * **必需**: `true`
* **有效输入类型：**
  * `html`
* **预期输出类型：**
  * `[HTML 元素]`

### `css_one`

* **名称**: `css_one`
* **说明**：与 `css`，但即使提供的 CSS 表达式选择了多个值，也只返回第一个值。 **请注意，以下函数的输出 `css_one` 函数的输出始终是一个 HTML 元素（包括开始和结束标签）。如果你想提取元素内容，可以随后执行 `element_text` 函数。**
* **参数**:
  * `css_expressions`
    * **类型**: `[字符串]`
    * **必需**: `true`
* **有效输入类型：**
  * `html`
* **预期输出类型：**
  * `HTML 元素`

## 字符串处理

### `amount_from_string`

* **名称**: `amount_from_string`
* **说明**：查找字符串中第一个数值并将其转换为浮点数。
* **参数**：不适用
* **有效输入类型：**
  * `字符串`
* **预期输出类型：**
  * `浮点数`

### `amount_range_from_string`

* **名称**: `amount_range_from_string`
* **说明**：查找字符串中所有数值并将其转换为浮点数。
* **参数**：不适用
* **有效输入类型：**
  * `字符串`
* **预期输出类型：**
  * `[浮点数]`

### `join`

* **名称**: `join`
* **说明**：将字符串列表合并为单个字符串。合并后的值之间使用以下 `separator` value。
* **参数**:
  * `separator`
    * **类型：** `字符串`
    * **是否必需：** `false`
    * **默认值：** `""`
* **有效输入类型：**
  * `[字符串]`
* **预期输出类型：**
  * `字符串`

### `regex_find_all`

* **名称**: `regex_find_all`
* **说明**：查找所有匹配给定正则表达式的字符串。
* **参数**:
  * `regex_pattern`
    * **类型：** `字符串`
    * **是否必需：** `true`
* **有效输入类型：**
  * `字符串`
* **预期输出类型：**
  * `[字符串]`

### `regex_search`

* **名称**: `regex_search`
* **说明**：查找匹配给定正则表达式的字符串。返回指定的匹配组（默认是 `0`).
* **参数**:
  * `regex_pattern`
    * **类型：** `字符串`
    * **是否必需：** `true`
  * `group_to_return`
    * **类型：** `整数`
    * **是否必需：** `false`
    * **默认值：** `0`
* **有效输入类型：**
  * `字符串`
* **预期输出类型：**
  * `字符串`

### `regex_substring`

* **名称**: `regex_substring`
* **说明**：将输入字符串中每个匹配给定正则表达式的部分替换为 `replacement` 值。对捕获组的反向引用（例如 `\\1`）在替换内容中受支持；空替换会删除匹配项。
* **参数**:
  * `regex_pattern`
    * **类型：** `字符串`
    * **是否必需：** `true`
  * `replacement`
    * **类型：** `字符串`
    * **是否必需：** `true`
* **有效输入类型：**
  * `字符串`
* **预期输出类型：**
  * `字符串`

## 通用

### `length`

* **名称**: `length`
* **说明**：获取数组长度。如果输入的是多维数组，函数将作用于最内层数组。
* **参数**：不适用
* **有效输入类型：**
  * `[一维数组]`
* **预期输出类型：**
  * `整数`

### `select_nth`

* **名称**: `select_nth`
* **说明**：返回数组中的第 n 个元素。索引从 0 开始。支持负索引以选择最后一个（`-1`）、倒数第二个（`-2`）等数组项。
* **参数**:
  * `index`
    * **类型：** `整数`
    * **是否必需：** `true`
* **有效输入类型：**
  * `[任意类型]`
* **预期输出类型：**
  * `任意类型`

### `convert_to_float`

* **名称**: `convert_to_float`
* **说明**：将字符串或整数转换为浮点数。
* **参数**：不适用
* **有效输入类型：**
  * `字符串`
  * `整数`
* **预期输出类型：**
  * `浮点数`

### `convert_to_int`

* **名称**: `convert_to_int`
* **说明**：将字符串或浮点数转换为整数。
* **参数**：不适用
* **有效输入类型：**
  * `字符串`
  * `浮点数`
* **预期输出类型：**
  * `整数`

### `convert_to_str`

* **名称**: `convert_to_str`
* **说明**：将整数或浮点数转换为字符串。
* **参数**：不适用
* **有效输入类型：**
  * `整数`
  * `浮点数`
* **预期输出类型：**
  * `字符串`

## 数学

### `average`

* **名称**: `average`
* **说明**：计算数组中各值的平均值。
* **参数**:
  * `round_precision`
    * **类型：** `整数`
    * **是否必需：** `false`
* **有效输入类型：**
  * `[整数]`
  * `[浮点数]`
* **预期输出类型：**
  * `浮点数`

### `最大`

* **名称**: `最大`
* **说明**：查找数组中的最大值。
* **参数**：不适用
* **有效输入类型：**
  * `[浮点数]`
  * `[整数]`
* **预期输出类型：**
  * `浮点数`
  * `整数`

### `最小`

* **名称**: `最小`
* **说明**：查找数组中的最小值。
* **参数**：不适用
* **有效输入类型：**
  * `[浮点数]`
  * `[整数]`
* **预期输出类型：**
  * `浮点数`
  * `整数`

### `product`

* **名称**: `product`
* **说明**：返回数组所有值的乘积。
* **参数**：不适用
* **有效输入类型：**
  * `[浮点数]`
  * `[整数]`
* **预期输出类型：**
  * `浮点数`
  * `整数`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.oxylabs.io/products/cn/web-scraper-api/features/custom-parser/writing-instructions-manually/list-of-functions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
