# 解析函数列表

您可以在以下位置找到每个函数的使用示例： [解析函数示例](https://developers.oxylabs.io/documentation/cn/zhua-qu-jie-jue-fang-an/web-scraper-api/features/custom-parser/writing-instructions-manually/list-of-functions/function-examples) 页面。

## HTML 处理

### `element_text`

* **名称**: `element_text`
* **说明**：从中提取文本 `html`。去除前后空白。
* **参数**：不适用
* **有效的输入类型：** `html`
* **期望的输出类型：** `str`

### `xpath`

* **名称**: `xpath`
* **说明**：在给定的输入值上执行 XPath 表达式。如果执行未产生结果，则使用数组中的下一个表达式。表达式中可使用 XSLT 函数。支持 XPath 1.0。支持 XSLT 1.0。
* **参数**:&#x20;
  * `xpath_expressions`
    * **类型**: `[str]`
    * **必需**: `true`
* **有效的输入类型：**&#x20;
  * `html`
* **期望的输出类型：**&#x20;
  * `[str]`
  * `[html]`
  * `str`
  * `float`
  * `bool`

### `xpath_one`

* **名称**: `xpath_one`
* **说明**：工作方式与 `xpath`相同，但即使提供的 XPath 选择了多个值，也只返回第一个值。
* **参数**:
  * `xpath_expressions`
    * **类型**: `[str]`
    * **必需**: `true`
* **有效的输入类型：**&#x20;
  * `html`
* **期望的输出类型：**
  * `str`
  * `html`
  * `str`
  * `float`
  * `bool`

### `css`

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

### `css_one`

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

## 字符串操作

### `amount_from_string`

* **名称**: `amount_from_string`
* **说明**：在字符串中查找第一个出现的数值并将其转换为浮点数。
* **参数**：不适用
* **有效的输入类型：**&#x20;
  * `str`
* **期望的输出类型：**
  * `float`

### `amount_range_from_string`

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

### `join`

* **名称**: `join`
* **说明**：将字符串列表连接为单个字符串。连接的值由 `分隔符` 值分隔。
* **参数**:&#x20;
  * `分隔符`
    * **类型：** `str`
    * **必需：** `false`
    * **默认：** `""`
* **有效的输入类型：**&#x20;
  * `[str]`
* **期望的输出类型：**
  * `str`

### `regex_find_all`

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

### `regex_search`

* **名称**: `regex_search`
* **说明**：查找与给定正则表达式匹配的字符串。返回指定的匹配组（默认返回 `0`).
* **参数**:&#x20;
  * `regex_pattern`
    * **类型：** `str`
    * **必需：** `true`
  * `group_to_return`
    * **类型：** `int`
    * **必需：** `false`
    * **默认：** `0`
* **有效的输入类型：**&#x20;
  * `str`
* **期望的输出类型：**
  * `str`

### `regex_substring`

* **名称**: `regex_substring`
* **说明**：查找与给定正则表达式匹配的字符串。返回指定的匹配组（默认返回 `0`).
* **参数**:&#x20;
  * `regex_pattern`
    * **类型：** `str`
    * **必需：** `true`
  * `group_to_return`
    * **类型：** `int`
    * **必需：** `false`
    * **默认：** `0`
* **有效的输入类型：**&#x20;
  * `str`
* **期望的输出类型：**
  * `str`

## 通用

### `length`

* **名称**: `length`
* **说明**：获取数组的长度。如果输入为多维数组，函数将在最内层数组上工作。
* **参数**：不适用
* **有效的输入类型：**&#x20;
  * `[OneDimensionalArray]`
* **期望的输出类型：**
  * `int`

### `select_nth`

* **名称**: `select_nth`
* **说明**：返回第 n 个数组元素。使用零基索引。支持负索引以从数组中选择最后一个（`-1`）、倒数第二个（`-2`）、… 项。
* **参数**:&#x20;
  * `index`
    * **类型：** `int`
    * **必需：** `true`
* **有效的输入类型：**&#x20;
  * `[AnyType]`
* **期望的输出类型：**
  * `AnyType`

### `convert_to_float`

* **名称**: `convert_to_float`
* **说明**：将字符串或整数转换为浮点数。
* **参数**：不适用
* **有效的输入类型：**&#x20;
  * `str`
  * `int`
* **期望的输出类型：**
  * `float`

### `convert_to_int`

* **名称**: `convert_to_int`
* **说明**：将字符串或浮点数转换为整数。
* **参数**：不适用
* **有效的输入类型：**&#x20;
  * `str`
  * `float`
* **期望的输出类型：**
  * `int`

### `convert_to_str`

* **名称**: `convert_to_str`
* **说明**：将整数或浮点数转换为字符串。
* **参数**：不适用
* **有效的输入类型：**&#x20;
  * `int`
  * `float`
* **期望的输出类型：**
  * `字符串`

## 数学

### `average`

* **名称**: `average`
* **说明**：计算数组中值的平均值。
* **参数**:
  * `round_precision`
    * **类型：** `int`
    * **必需：** `false`
* **有效的输入类型：**&#x20;
  * `[int]`
  * `[float]`
* **期望的输出类型：**
  * `float`

### `max`

* **名称**: `max`
* **说明**：在数组中查找最大值。
* **参数**：不适用
* **有效的输入类型：**&#x20;
  * `[float]`
  * `[int]`
* **期望的输出类型：**
  * `float`
  * `int`

### `min`

* **名称**: `min`
* **说明**：在数组中查找最小值。
* **参数**：不适用
* **有效的输入类型：**&#x20;
  * `[float]`
  * `[int]`
* **期望的输出类型：**
  * `float`
  * `int`

### `product`

* **名称**: `product`
* **说明**：返回所有数组值的乘积。
* **参数**：不适用
* **有效的输入类型：**&#x20;
  * `[float]`
  * `[int]`
* **期望的输出类型：**
  * `float`
  * `int`
