HTML#
HTML 节点提供各种操作,帮助你在 n8n 中处理 HTML。
¥The HTML node provides operations to help you work with HTML in n8n.
HTML Extract node
从 0.213.0 版本开始,HTML 节点取代了 HTML Extract 节点。如果你使用的是旧版本的 n8n,仍然可以查看 HTML 提取节点文档。
¥The HTML node replaces the HTML Extract node from version 0.213.0 on. If you're using an older version of n8n, you can still view the HTML Extract node documentation.
Cross-site scripting
使用 HTML 节点生成 HTML 模板时,可以引入 XSS(跨站脚本攻击)。这是一个安全风险。谨慎使用不受信任的输入。
¥When using the HTML node to generate an HTML template you can introduce XSS (cross-site scripting). This is a security risk. Be careful with un-trusted inputs.
操作#
¥Operations
- 生成 HTML 模板:使用此操作创建 HTML 模板。此功能允许你从工作流中提取数据并将其输出为 HTML。
¥Generate HTML template: Use this operation to create an HTML template. This allows you to take data from your workflow and output it as HTML.
- 提取 HTML 内容:从 HTML 格式的源文件中提取内容。源可以是 JSON 或二进制文件 (
.html)。
¥Extract HTML content: Extract contents from an HTML-formatted source. The source can be in JSON or a binary file (.html).
- 转换为 HTML 表格:将内容转换为 HTML 表格
¥Convert to HTML Table: Convert content to an HTML table.
节点参数和选项取决于你选择的操作。请参阅以下各节,了解有关配置每个操作的更多详细信息。
¥The node parameters and options depend on the operation you select. Refer to the sections below for more details on configuring each operation.
生成 HTML 模板#
¥Generate HTML template
创建 HTML 模板此功能允许你从工作流中提取数据并将其输出为 HTML。
¥Create an HTML template. This allows you to take data from your workflow and output it as HTML.
你可以包含:
¥You can include:
- 标准 HTML
¥Standard HTML
<style>标签中的 CSS。
¥CSS in <style> tags.
<script>标签中的 JavaScript。n8n 不会执行 JavaScript。
¥JavaScript in <script> tags. n8n doesn't execute the JavaScript.
- 用
{{}}封装的表达式。
¥Expressions, wrapped in {{}}.
你可以在模板中使用 表达式,包括 n8n 的 内置方法和变量。
¥You can use Expressions in the template, including n8n's Built-in methods and variables.
提取 HTML 内容#
¥Extract HTML Content
从 HTML 格式的源文件中提取内容。源可以是 JSON 或二进制文件 (.html)。
¥Extract contents from an HTML-formatted source. The source can be in JSON or a binary file (.html).
使用这些参数:
¥Use these parameters:
源数据#
¥Source Data
选择 HTML 内容的源类型。选择以下选项:
¥Select the source type for your HTML content. Choose between:
- JSON:如果你选择此源数据,请输入“JSON 属性”:包含要提取的 HTML 的输入的名称。该属性可以包含一个字符串或一个字符串数组。
¥JSON: If you select this source data, enter the JSON Property: the name of the input containing the HTML you want to extract. The property can contain a string or an array of strings.
- 二进制:如果你选择此源数据,请输入“输入二进制字段”:包含要提取的 HTML 的输入的名称。该属性可以包含一个字符串或一个字符串数组。
¥Binary: If you select this source data, enter the Input Binary Field: the name of the input containing the HTML you want to extract. The property can contain a string or an array of strings.
提取值#
¥Extraction Values
- 密钥:输入用于保存提取值的键。
¥Key: Enter the key to save the extracted value under.
- CSS 选择器:输入要搜索的 CSS 选择器。
¥CSS Selector: Enter the CSS selector to search for.
- 返回值:选择要返回的数据类型。选择以下选项:
¥Return Value: Select the type of data to return. Choose from:
-
属性:从元素中返回类似
class的属性值。¥Attribute: Return an attribute value like
classfrom an element.- 如果你选择此选项,请输入要返回值的属性名称。
¥If you select this option, enter the name of the Attribute to return the value of.
-
HTML:返回元素包含的 HTML 代码。
¥HTML: Return the HTML that the element contains.
-
文本:返回元素的文本内容。
¥Text: Return the text content of the element.
- 如果选择此选项,你还可以在“跳过选择器”中输入以逗号分隔的选择器列表以跳过。
¥If you choose this option, you can also enter a comma-separated list of selectors to skip in the Skip Selectors.
-
值:返回输入框、下拉框或文本区域的值。
¥Value: Return the value of an input, select, or text area.
-
返回数组:选择是否将多个提取值作为数组(已启用)或单个字符串(已禁用)返回。
¥Return Array: Choose whether to return multiple extraction values as an array (turned on) or as a single string (turned off).
提取 HTML 内容选项#
¥Extract HTML Content options
你还可以使用以下选项配置此操作:
¥You can also configure this operation with these options:
- 修剪值:控制是否删除值开头和结尾的所有空格和换行符(已启用)或保留它们(已禁用)。
¥Trim Values: Controls whether to remove all spaces and newlines from the beginning and end of the values (turned on) or leaves them (turned off).
- 清理文本:控制是否移除前导空格、尾随空格和换行符,以及将多个连续空格合并为一个空格(启用)或保留原样(禁用)。
¥Clean Up Text: Controls whether to remove leading whitespaces, trailing whitespaces, and line breaks (newlines) and condense multiple consecutive whitespaces into a single space (turned on) or to leave them as-is (turned off).
转换为 HTML 表格#
¥Convert to HTML Table
此操作需要来自另一个节点的数据。没有参数。包含以下选项:
¥This operation expects data from another node. It has no parameters. It includes these options:
- 首字母大写:控制是否将表头首字母大写(已启用)或不大写(已禁用)。
¥Capitalize Headers: Controls whether to capitalize the table's headers (turned on) or not (turned off).
- 自定义样式:控制是否使用自定义样式(启用)或不使用(禁用)。
¥Custom Styling: Controls whether to use custom styling (turned on) or not (turned off).
- 标题:输入要添加到表格的标题。
¥Caption: Enter a caption to add to the table.
- 表属性:输入要应用于
<table>的任何属性,例如样式属性。
¥Table Attributes: Enter any attributes to apply to the <table>, such as style attributes.
- 标头属性:输入要应用于表格标题
<th>的任何属性。
¥Header Attributes: Enter any attributes to apply to the table's headers <th>.
- 行属性:输入要应用于表格行
<tr>的任何属性。
¥Row Attributes: Enter any attributes to apply to the table's rows <tr>.
- 单元格属性:输入要应用于表格单元格
<td>的任何属性。
¥Cell Attributes: Enter any attributes to apply to the table's cells <td>.
模板和示例#
¥Templates and examples