即使我们没有某个应用的专用节点或现有操作,您仍可在工作流中使用该应用。通过 HTTP 请求节点,您可以调用任何 API 端点,并将返回数据用于工作流中。
主要应用场景:
- 连接 n8n 尚未集成的应用与服务
- 网页抓取
运作原理
该工作流可分为三个分支,每个分支具有特定功能:
1.项目拆分(HTTP 请求 - 获取模拟专辑数据):
-
工作流始于手动触发(点击"执行"按钮时启动)。
-
通过 HTTP 请求从"jsonplaceholder.typicode.com/albums"获取模拟...
-
使用 Item Lists 节点将获取的数据拆分为独立项目,便于后续管理操作。
2.数据抓取(HTTP 请求-获取维基百科页面及 HTML 提取):
-
该工作流的另一分支通过向"en.wikipedia.org/wiki/Specia... HTTP 请求来获取随机维基百科页面。
-
HTML 提取节点从获取的维基百科页面中抽取文章标题。
3.分页处理(最终分支负责处理 GitHub API 请求的分页问题):
- 它向"api.github.com/users/that-... HTTP 请求,其中的页码和每页项目数等参数由 Set 节点动态设置。
- 该工作流使用条件判断(If - 是否完成?)来检查是否还有更多页面需要获取,并相应地递增页码(Set - 增加页码)。


- 这个过程会重复执行,直到获取所有页面数据,从而实现完整的数据收集。
其他
- 原文:点击打开
- 代码
json
{
"name": "7、 HTTP Request",
"nodes": [
{
"parameters": {},
"id": "1ccf8e89-1b6c-41a0-969e-f5042476f071",
"name": "On clicking 'execute'",
"type": "n8n-nodes-base.manualTrigger",
"position": [
-240,
-112
],
"typeVersion": 1
},
{
"parameters": {
"content": "## HTTP Request\n\n此 workflow 展示了 HTTP request 节点最常见的使用场景,以及如何处理其输出\n\n点击 `Execute Workflow` 按钮,并双击节点以查看输入和输出的 items。\n",
"height": 200,
"width": 440
},
"id": "cd906a35-97ee-4441-a917-a08dd15b9e3c",
"name": "Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-784,
-160
],
"typeVersion": 1
},
{
"parameters": {
"content": "## 3. Handle Pagination\n有时你需要多次发起相同的请求以获取所需的所有数据(分页)。\n\n### 分页流程如下:\n1. 遍历输入来源的各个页面(`HTTP Request` 节点,名为 \"Get my Starts\")\n2. 在每次循环结束时增加页码(通过 `set` 节点,名为 \"Increment Page\" 完成)\n3. 当没有更多页面时停止循环(在 `If` 节点,名为 \"Are we Finished?\" 检查)\n",
"height": 460.847917534361,
"width": 986.3743856726365
},
"id": "bc66822c-982b-43a3-8376-2a45ddde2674",
"name": "Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
112,
80
],
"typeVersion": 1
},
{
"parameters": {
"values": {
"number": [
{
"name": "page"
},
{
"name": "perpage",
"value": 15
}
],
"string": [
{
"name": "githubUser",
"value": "that-one-tom"
}
]
},
"options": {}
},
"id": "747b21b5-3189-4d0e-8350-de39d6f35ac7",
"name": "Set",
"type": "n8n-nodes-base.set",
"position": [
176,
320
],
"typeVersion": 1
},
{
"parameters": {
"content": "## 2. Data Scraping\n在此示例中,我们使用 `HTTP request` 节点从 n8n 博客获取标题,然后使用 `HTML extract` 节点进行处理。\n\n",
"height": 280,
"width": 680
},
"id": "4e238485-e573-45d2-8993-bc09d693e5e2",
"name": "Note6",
"type": "n8n-nodes-base.stickyNote",
"position": [
112,
-224
],
"typeVersion": 1,
"disabled": true
},
{
"parameters": {
"content": "## 1. Split into items\n在此示例中,我们将 `HTTP Request` 节点的 body 拆分为更易于管理的 items。",
"height": 280,
"width": 500
},
"id": "f1b631b0-8562-4e8c-b27e-319fb503c4c7",
"name": "Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
112,
-528
],
"typeVersion": 1
},
{
"parameters": {
"fieldToSplitOut": "body",
"options": {}
},
"id": "7265c3a9-391c-4504-9972-776a42914b9f",
"name": "Item Lists - Create Items from Body",
"type": "n8n-nodes-base.itemLists",
"position": [
352,
-416
],
"notesInFlow": false,
"typeVersion": 1,
"notes": "Create Items from Body"
},
{
"parameters": {
"sourceData": "binary",
"extractionValues": {
"values": [
{
"key": "ArticleTitle",
"cssSelector": "#firstHeading"
}
]
},
"options": {}
},
"id": "ed096820-cf58-4495-862d-438018e8590b",
"name": "HTML Extract - Extract Article Title",
"type": "n8n-nodes-base.htmlExtract",
"position": [
336,
-112
],
"typeVersion": 1
},
{
"parameters": {
"fieldToSplitOut": "body",
"options": {}
},
"id": "d54adebf-ba40-4821-a31a-28b4c6500b0a",
"name": "Item Lists - Fetch Body",
"type": "n8n-nodes-base.itemLists",
"position": [
544,
320
],
"typeVersion": 1,
"alwaysOutputData": true
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{$node[\"HTTP Request - Get my Stars\"].json[\"body\"]}}",
"operation": "isEmpty"
}
]
}
},
"id": "ee678e31-f8ce-4138-878c-6c4526002141",
"name": "If - Are we finished?",
"type": "n8n-nodes-base.if",
"position": [
720,
320
],
"executeOnce": true,
"typeVersion": 1
},
{
"parameters": {
"values": {
"string": [
{
"name": "page",
"value": "={{$node[\"Set\"].json[\"page\"]++}}"
}
]
},
"options": {}
},
"id": "8d5c2863-1b3d-4353-93bf-c96d27bc57e1",
"name": "Set - Increment Page",
"type": "n8n-nodes-base.set",
"position": [
944,
352
],
"executeOnce": true,
"typeVersion": 1
},
{
"parameters": {
"url": "https://jsonplaceholder.typicode.com/albums",
"options": {
"response": {
"response": {
"fullResponse": true
}
}
}
},
"id": "291ac0c1-85c9-490a-9475-279cfb8eb624",
"name": "HTTP Request - Get Mock Albums",
"type": "n8n-nodes-base.httpRequest",
"position": [
176,
-416
],
"typeVersion": 3
},
{
"parameters": {
"url": "https://en.wikipedia.org/wiki/Special:Random",
"options": {
"redirect": {
"redirect": {
"followRedirects": true
}
},
"response": {
"response": {
"responseFormat": "file"
}
}
}
},
"id": "54c78fbb-70c7-43c7-8a4f-0b4f4cabb1b4",
"name": "HTTP Request - Get Wikipedia Page",
"type": "n8n-nodes-base.httpRequest",
"position": [
160,
-112
],
"typeVersion": 3
},
{
"parameters": {
"url": "=https://api.github.com/users/{{$node[\"Set\"].json[\"githubUser\"]}}/starred",
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "per_page",
"value": "={{$node[\"Set\"].json[\"perpage\"]}}"
},
{
"name": "page",
"value": "={{$node[\"Set\"].json[\"page\"]}}"
}
]
},
"options": {
"response": {
"response": {
"fullResponse": true
}
}
}
},
"id": "75d99d10-dfd5-4d84-b3ce-d7efe76c522c",
"name": "HTTP Request - Get my Stars",
"type": "n8n-nodes-base.httpRequest",
"position": [
352,
320
],
"typeVersion": 3
}
],
"pinData": {},
"connections": {
"Set": {
"main": [
[
{
"node": "HTTP Request - Get my Stars",
"type": "main",
"index": 0
}
]
]
},
"Set - Increment Page": {
"main": [
[
{
"node": "HTTP Request - Get my Stars",
"type": "main",
"index": 0
}
]
]
},
"If - Are we finished?": {
"main": [
[],
[
{
"node": "Set - Increment Page",
"type": "main",
"index": 0
}
]
]
},
"On clicking 'execute'": {
"main": [
[
{
"node": "Set",
"type": "main",
"index": 0
},
{
"node": "HTTP Request - Get Mock Albums",
"type": "main",
"index": 0
},
{
"node": "HTTP Request - Get Wikipedia Page",
"type": "main",
"index": 0
}
]
]
},
"Item Lists - Fetch Body": {
"main": [
[
{
"node": "If - Are we finished?",
"type": "main",
"index": 0
}
]
]
},
"HTTP Request - Get my Stars": {
"main": [
[
{
"node": "Item Lists - Fetch Body",
"type": "main",
"index": 0
}
]
]
},
"HTTP Request - Get Mock Albums": {
"main": [
[
{
"node": "Item Lists - Create Items from Body",
"type": "main",
"index": 0
}
]
]
},
"HTTP Request - Get Wikipedia Page": {
"main": [
[
{
"node": "HTML Extract - Extract Article Title",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "36c9e0e9-a945-4311-b503-24e31922e954",
"meta": {
"instanceId": "93bc91f5b94c286bd0f4f65621745c9fee427fafd468de9d56a6b7a434a37fbc"
},
"id": "4cBzGMvzTQR4Y4Ri",
"tags": []
}