8
n8n 中文网amn8n.com

10 - 商业版图追踪器

中级

这是一个Market Research, Multimodal AI领域的自动化工作流,包含 15 个节点。主要使用 If, Code, Airtable, HttpRequest, GoogleSheets 等节点。 使用SerpAPI、Google表格和Airtable的每日竞争对手研究自动化

前置要求
  • Airtable API Key
  • 可能需要目标 API 的认证凭证
  • Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "name": "10 - 商业版图追踪器",
  "tags": [],
  "nodes": [
    {
      "id": "1be5e364-b985-4ce4-bb52-5f4d4afc8481",
      "name": "🕒 自动运行(定时触发)",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -2040,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 9
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7e5d5597-0e13-477d-af55-2847cdd4b89c",
      "name": "📄 读取公司表格",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -1820,
        0
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_GOOGLE_SHEET_ID_HERE/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_GOOGLE_SHEET_ID_HERE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_GOOGLE_SHEET_ID_HERE/edit?usp=drivesdk",
          "cachedResultName": "Companies List"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "YOUR_GOOGLE_SHEETS_CREDENTIAL_ID",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4
    },
    {
      "id": "0942f8f7-220c-48fc-bda0-43b250981475",
      "name": "🧹 清理并格式化公司列表",
      "type": "n8n-nodes-base.code",
      "position": [
        -1600,
        0
      ],
      "parameters": {
        "jsCode": "const companies = [];\n\nfor (const item of $input.all()) {\n  // Get company name from the correct field key: \"List\"\n  const companyName = item.json.List;\n\n  if (companyName && companyName.trim() !== '') {\n    companies.push({\n      company: companyName.trim(),\n      row: item.json.row_number || companies.length + 2\n    });\n  }\n}\n\n// Return each company as a separate item\nreturn companies.map(company => ({ json: company }));"
      },
      "typeVersion": 2
    },
    {
      "id": "dd0127ef-28ef-4928-8cdc-6cf0627ac365",
      "name": "🔁 循环遍历公司",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -1380,
        0
      ],
      "parameters": {
        "options": {},
        "batchSize": 100
      },
      "typeVersion": 3
    },
    {
      "id": "ee903349-6643-4c97-862c-bd50d2abcd8d",
      "name": "🌍 搜索公司竞争对手(SerpAPI)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1160,
        0
      ],
      "parameters": {
        "url": "https://serpapi.com/search.json",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        },
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "q",
              "value": "={{ $json.company }} competitors"
            },
            {
              "name": "hl",
              "value": "en"
            },
            {
              "name": "gl",
              "value": "us"
            },
            {
              "name": "api_key",
              "value": "YOUR_SERPAPI_KEY_HERE"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "a5f9d7d7-a7b2-4325-bbe9-c2feb053f98a",
      "name": "🧠 从搜索结果提取竞争对手数据",
      "type": "n8n-nodes-base.code",
      "position": [
        -940,
        0
      ],
      "parameters": {
        "jsCode": "const inputData = $input.all();\nconst results = [];\n\nfor (const item of inputData) {\n  const searchResults = item.json;\n\n  // === Helper Functions (same as before) ===\n\n  function extractCompanyName(searchData) {\n    if (searchData.search_parameters?.q) {\n      const query = searchData.search_parameters.q.toLowerCase();\n      const cleanQuery = query\n        .replace(/competitors?/gi, '')\n        .replace(/competition/gi, '')\n        .replace(/vs/gi, '')\n        .replace(/alternatives?/gi, '')\n        .trim();\n      const companyName = cleanQuery.split(' ')[0];\n      return companyName.charAt(0).toUpperCase() + companyName.slice(1);\n    }\n\n    if (searchData.organic_results?.[0]?.title) {\n      const title = searchData.organic_results[0].title;\n      const match = title.match(/(\\w+)\\s+competitors?/i);\n      if (match) return match[1];\n    }\n\n    return \"Unknown Company\";\n  }\n\n  function extractCompetitors(searchData) {\n    const competitors = new Set();\n\n    if (searchData.related_questions) {\n      searchData.related_questions.forEach(q => {\n        q.list?.forEach(item => {\n          const clean = item.replace(/\\.$/, '').trim();\n          if (clean.length > 1) competitors.add(clean);\n        });\n      });\n    }\n\n    if (searchData.ai_overview?.text_blocks) {\n      searchData.ai_overview.text_blocks.forEach(block => {\n        block.list?.forEach(item => {\n          const clean = item.title?.replace(/:$/, '').trim();\n          if (clean?.length > 1) competitors.add(clean);\n        });\n      });\n    }\n\n    if (searchData.organic_results) {\n      searchData.organic_results.forEach(result => {\n        const snippet = result.snippet;\n        if (snippet) {\n          const patterns = [\n            /competitors?[^.]*?include[^.]*?([A-Z][a-zA-Z\\s,&.]+)/gi,\n            /rivals?[^.]*?include[^.]*?([A-Z][a-zA-Z\\s,&.]+)/gi,\n            /competition[^.]*?from[^.]*?([A-Z][a-zA-Z\\s,&.]+)/gi\n          ];\n          patterns.forEach(pattern => {\n            const matches = snippet.match(pattern);\n            if (matches) {\n              matches.forEach(match => {\n                match\n                  .split(/,|\\sand\\s|&/)\n                  .map(name => name.replace(/[^a-zA-Z\\s]/g, '').trim())\n                  .forEach(name => {\n                    if (name.length > 2 && !name.toLowerCase().includes('competitor'))\n                      competitors.add(name);\n                  });\n              });\n            }\n          });\n        }\n      });\n    }\n\n    if (searchData.answer_box?.expanded_list) {\n      searchData.answer_box.expanded_list.forEach(item => {\n        if (item.title) competitors.add(item.title);\n      });\n    }\n\n    return Array.from(competitors).slice(0, 10);\n  }\n\n  function getTopSource(searchData) {\n    return searchData.organic_results?.[0]?.link || null;\n  }\n\n  // === Main Logic ===\n  try {\n    const company = extractCompanyName(searchResults);\n    const competitorsList = extractCompetitors(searchResults);\n    const topSource = getTopSource(searchResults);\n\n    results.push({\n      json: {\n        company,\n        competitors: competitorsList.join(', ') || 'No competitors found',\n        competitor_count: competitorsList.length,\n        top_source: topSource,\n        search_query: searchResults.search_parameters?.q || 'N/A',\n        total_results: searchResults.search_information?.total_results || 0,\n        extraction_timestamp: new Date().toISOString()\n      }\n    });\n  } catch (err) {\n    results.push({\n      json: {\n        error: `Extraction failed: ${err.message}`,\n        company: \"Unknown\",\n        competitors: \"\",\n        competitor_count: 0,\n        top_source: null\n      }\n    });\n  }\n}\n\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "20193daa-c689-4311-ad39-9f696794712d",
      "name": "🧐 是否存在竞争对手?",
      "type": "n8n-nodes-base.if",
      "position": [
        -720,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "8a7b6c5d-4321-0987-6543-210fedcba987",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.competitors }}",
              "rightValue": "No competitors found"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "1f513736-3963-4045-9eaa-4df3cebfc0e3",
      "name": "📊 记录到结果表格",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -500,
        -100
      ],
      "parameters": {
        "columns": {
          "value": {
            "Source": "={{ $json.top_source }}",
            "Company": "={{ $json.company }}",
            "Competitors": "={{ $json.competitors }}",
            "Total Results": "={{ $json.total_results }}"
          },
          "schema": [
            {
              "id": "Company",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Company",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Competitors",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Competitors",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Total Results",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Total Results",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Source",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Source",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Company"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {
          "useAppend": true,
          "cellFormat": "USER_ENTERED"
        },
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_RESULTS_GOOGLE_SHEET_ID_HERE/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_RESULTS_GOOGLE_SHEET_ID_HERE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_RESULTS_GOOGLE_SHEET_ID_HERE/edit?usp=drivesdk",
          "cachedResultName": "Companies Result"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "YOUR_GOOGLE_SHEETS_CREDENTIAL_ID",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4
    },
    {
      "id": "d39b91c7-a3c0-45eb-b926-2d668262a899",
      "name": "❌ 记录无结果的公司",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -500,
        100
      ],
      "parameters": {
        "columns": {
          "value": {
            "Source": "Null",
            "Company": "={{ $json.company }}",
            "Competitors": "No Competetitors Found",
            "Total Results": "0"
          },
          "schema": [
            {
              "id": "Company",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Company",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Competitors",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Competitors",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Total Results",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Total Results",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Source",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Source",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {
          "useAppend": true,
          "cellFormat": "USER_ENTERED"
        },
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_RESULTS_GOOGLE_SHEET_ID_HERE/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_RESULTS_GOOGLE_SHEET_ID_HERE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_RESULTS_GOOGLE_SHEET_ID_HERE/edit?usp=drivesdk",
          "cachedResultName": "Companies Result"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "YOUR_GOOGLE_SHEETS_CREDENTIAL_ID",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4
    },
    {
      "id": "7910cb3e-88e7-4716-82ad-89bec10409a8",
      "name": "🗃️ 同步到 Airtable",
      "type": "n8n-nodes-base.airtable",
      "position": [
        -280,
        0
      ],
      "parameters": {
        "base": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_AIRTABLE_BASE_ID_HERE",
          "cachedResultUrl": "https://airtable.com/YOUR_AIRTABLE_BASE_ID_HERE",
          "cachedResultName": "Test"
        },
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_AIRTABLE_TABLE_ID_HERE",
          "cachedResultUrl": "https://airtable.com/YOUR_AIRTABLE_BASE_ID_HERE/YOUR_AIRTABLE_TABLE_ID_HERE",
          "cachedResultName": "Table 1"
        },
        "columns": {
          "value": {
            "Source": "={{ $json.Source }}",
            "Company": "={{ $json.Company }}",
            "Competitors": "={{ $json.Competitors }}",
            "Total Results": "={{ $json[\"Total Results\"] }}"
          },
          "schema": [
            {
              "id": "id",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": true,
              "required": false,
              "displayName": "id",
              "defaultMatch": true
            },
            {
              "id": "Company",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Company",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Competitors",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Competitors",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Total Results",
              "type": "number",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Total Results",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Source",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Source",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Company"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "upsert"
      },
      "credentials": {
        "airtableTokenApi": {
          "id": "YOUR_AIRTABLE_CREDENTIAL_ID",
          "name": "Airtable Personal Access Token account"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "b299cf8f-6b5e-48f2-adb4-2794ad4220aa",
      "name": "便签说明",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2140,
        -340
      ],
      "parameters": {
        "color": 5,
        "width": 280,
        "height": 640,
        "content": "## 自动运行(定时触发)"
      },
      "typeVersion": 1
    },
    {
      "id": "e21ba623-5589-4781-a131-31afbee80431",
      "name": "便签说明1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1840,
        -340
      ],
      "parameters": {
        "color": 3,
        "width": 600,
        "height": 640,
        "content": "## 循环遍历公司"
      },
      "typeVersion": 1
    },
    {
      "id": "38ce6a00-5b57-47a2-9cce-e2deaa67e285",
      "name": "便签说明2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1220,
        -340
      ],
      "parameters": {
        "color": 4,
        "width": 220,
        "height": 640,
        "content": "## 搜索公司竞争对手(SerpAPI)"
      },
      "typeVersion": 1
    },
    {
      "id": "78b206db-221d-426c-aa15-1115c2266cc8",
      "name": "便签说明3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -980,
        -340
      ],
      "parameters": {
        "width": 420,
        "height": 640,
        "content": "## 提取与检查竞争对手"
      },
      "typeVersion": 1
    },
    {
      "id": "6ef49329-b2a7-44ad-9226-d2c61dc996e7",
      "name": "便签说明4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -540,
        -340
      ],
      "parameters": {
        "color": 6,
        "width": 460,
        "height": 640,
        "content": "## 记录结果到表格与 Airtable"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "connections": {
    "🧐 Has Competitors?": {
      "main": [
        [
          {
            "node": "📊 Log to Result Sheet",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "❌ Log Companies Without Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "📊 Log to Result Sheet": {
      "main": [
        [
          {
            "node": "🗃️ Sync to Airtable",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "🔁 Loop Over Companies": {
      "main": [
        [],
        [
          {
            "node": "🌍 Search Company Competitors (SerpAPI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "📄 Read Companies Sheet": {
      "main": [
        [
          {
            "node": "🧹 Clean & Format Company List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "🕒 Auto Run (Scheduled)": {
      "main": [
        [
          {
            "node": "📄 Read Companies Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "🧹 Clean & Format Company List": {
      "main": [
        [
          {
            "node": "🔁 Loop Over Companies",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "❌ Log Companies Without Results": {
      "main": [
        [
          {
            "node": "🗃️ Sync to Airtable",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "🧠 Extract Competitor Data from Search": {
      "main": [
        [
          {
            "node": "🧐 Has Competitors?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "🌍 Search Company Competitors (SerpAPI)": {
      "main": [
        [
          {
            "node": "🧠 Extract Competitor Data from Search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 市场调研, 多模态 AI

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量15
分类2
节点类型8
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
Avkash Kakdiya

Avkash Kakdiya

@itechnotion

🚀 Founder of iTechNotion — we build custom AI-powered automation workflows for startups, agencies, and founders. 💡 Specializing in agentic AI systems, content automation, sales funnels, and digital workers. 🔧 14+ years in tech | Building scalable no-code/low-code solutions using n8n, OpenAI, and other API-first tools. 📬 Let’s automate what slows you down.

外部链接
在 n8n.io 查看

分享此工作流