工作流文件
competitor-monitor.json
{
"name": "竞品价格监控",
"nodes": [
{
"parameters": {
"rule": {
"interval": [
{
"field": "hours",
"hoursInterval": 6
}
]
}
},
"id": "10386c09-b0f9-5329-a86e-f3091dcf5b4a",
"name": "每 6 小时",
"type": "n8n-nodes-base.scheduleTrigger",
"typeVersion": 1.2,
"position": [
0,
0
]
},
{
"parameters": {
"documentId": {
"__rl": true,
"value": "替换成你的表格 ID",
"mode": "id"
},
"sheetName": {
"__rl": true,
"value": "竞品列表",
"mode": "name"
},
"options": {}
},
"id": "1dd4e84b-2ddb-51f7-be63-9d8a3a0fd4bf",
"name": "读取竞品列表",
"type": "n8n-nodes-base.googleSheets",
"typeVersion": 4.5,
"position": [
240,
0
]
},
{
"parameters": {
"url": "={{ $json['链接'] }}",
"options": {
"batching": {
"batch": {
"batchSize": 1,
"batchInterval": 3000
}
},
"response": {
"response": {
"responseFormat": "text"
}
}
}
},
"id": "e992255e-5c8a-53cd-bc71-647983e939ff",
"name": "抓取商品页",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
480,
0
]
},
{
"parameters": {
"jsCode": "// 每个竞品一条:从页面里找出价格,和表格里的「上次价格」比。\n// 不同网站的价格写法不一样,下面两条规则按你要监控的页面改;找不到价格的会在「没找到价格」一列标出来。\nconst rows = $('读取竞品列表').all();\nreturn $input.all().map((item, i) => {\n const row = rows[i].json;\n const html = String(item.json.data || '');\n const m = html.match(/\"price\"\\s*:\\s*\"?(\\d+(?:\\.\\d+)?)/) || html.match(/[¥¥]\\s*(\\d+(?:\\.\\d+)?)/);\n const price = m ? Number(m[1]) : null;\n const last = Number(row['上次价格']) || null;\n const limit = Number(row['提醒阈值']) || 5; // 百分比;表格里不填就按 5%\n const change = price && last ? Number(((price - last) / last * 100).toFixed(1)) : null;\n return { json: {\n 名称: row['名称'], 链接: row['链接'], 上次价格: last, 价格: price, 变化: change,\n 超过阈值: change !== null && Math.abs(change) >= limit,\n 没找到价格: price === null,\n 时间: $now.setZone('Asia/Shanghai').toFormat('yyyy-MM-dd HH:mm'),\n } };\n});"
},
"id": "22a3f1ef-ab70-5553-8634-48a19af45655",
"name": "解析价格、和上次比",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
720,
0
]
},
{
"parameters": {
"operation": "append",
"documentId": {
"__rl": true,
"value": "替换成你的表格 ID",
"mode": "id"
},
"sheetName": {
"__rl": true,
"value": "价格历史",
"mode": "name"
},
"columns": {
"mappingMode": "autoMapInputData",
"value": {}
},
"options": {}
},
"id": "01851508-b913-54f2-975e-d31721420e19",
"name": "写入价格历史",
"type": "n8n-nodes-base.googleSheets",
"typeVersion": 4.5,
"position": [
960,
-200
]
},
{
"parameters": {
"operation": "appendOrUpdate",
"documentId": {
"__rl": true,
"value": "替换成你的表格 ID",
"mode": "id"
},
"sheetName": {
"__rl": true,
"value": "竞品列表",
"mode": "name"
},
"columns": {
"mappingMode": "defineBelow",
"matchingColumns": [
"链接"
],
"value": {
"链接": "={{ $json['链接'] }}",
"上次价格": "={{ $json['价格'] ?? $json['上次价格'] }}"
}
},
"options": {}
},
"id": "45d082be-1f16-5a8d-ade0-d62c5c3538dd",
"name": "更新上次价格",
"type": "n8n-nodes-base.googleSheets",
"typeVersion": 4.5,
"position": [
960,
0
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "loose"
},
"conditions": [
{
"id": "0d421ab8-6569-5d16-89fd-7faf5f890255",
"leftValue": "={{ $json['超过阈值'] }}",
"rightValue": "",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "c94c3d7a-06ec-5b67-ab43-267a2ba89db1",
"name": "价格变化超过阈值?",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
960,
200
]
},
{
"parameters": {
"method": "POST",
"url": "https://api.deepseek.com/chat/completions",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{ JSON.stringify({ model: 'deepseek-chat', messages: [{ role: 'user', content: '你是电商运营顾问。竞品「' + $json['名称'] + '」价格从 ' + $json['上次价格'] + ' 元变成 ' + $json['价格'] + ' 元(' + $json['变化'] + '%)。请用不超过 120 字分析:对方为什么可能这样调价、我们要不要跟,给 2 条具体建议。' }] }) }}",
"options": {}
},
"id": "a9bfda65-fdd6-55a4-b549-0e306ce3699a",
"name": "AI 分析",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1200,
200
]
},
{
"parameters": {
"method": "POST",
"url": "https://open.feishu.cn/open-apis/bot/v2/hook/替换成你的飞书机器人地址",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{ JSON.stringify({ msg_type: 'text', content: { text: '🔔 竞品「' + $('价格变化超过阈值?').item.json['名称'] + '」价格变动:' + $('价格变化超过阈值?').item.json['上次价格'] + ' → ' + $('价格变化超过阈值?').item.json['价格'] + ' 元(' + $('价格变化超过阈值?').item.json['变化'] + '%)\\n🤖 AI 分析:' + $json.choices[0].message.content + '\\n' + $('价格变化超过阈值?').item.json['链接'] } }) }}",
"options": {}
},
"id": "df4ec9d0-a236-5a8d-94ef-e1071cd66e7d",
"name": "推送飞书",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1440,
200
]
}
],
"connections": {
"每 6 小时": {
"main": [
[
{
"node": "读取竞品列表",
"type": "main",
"index": 0
}
]
]
},
"读取竞品列表": {
"main": [
[
{
"node": "抓取商品页",
"type": "main",
"index": 0
}
]
]
},
"抓取商品页": {
"main": [
[
{
"node": "解析价格、和上次比",
"type": "main",
"index": 0
}
]
]
},
"解析价格、和上次比": {
"main": [
[
{
"node": "写入价格历史",
"type": "main",
"index": 0
},
{
"node": "更新上次价格",
"type": "main",
"index": 0
},
{
"node": "价格变化超过阈值?",
"type": "main",
"index": 0
}
]
]
},
"价格变化超过阈值?": {
"main": [
[
{
"node": "AI 分析",
"type": "main",
"index": 0
}
],
[]
]
},
"AI 分析": {
"main": [
[
{
"node": "推送飞书",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1",
"timezone": "Asia/Shanghai"
},
"pinData": {}
}
下载后在 n8n、Dify 里导入;n8n 也可以直接在画布上按 Ctrl+V 粘贴。