8
n8n 中文网amn8n.com

Instagram潜在客户生成

高级

这是一个Lead Generation, AI RAG领域的自动化工作流,包含 18 个节点。主要使用 Set, Code, Postgres, SplitOut, HttpRequest 等节点。 使用Apify、GPT和PostgreSQL自动化Instagram影响者潜在客户收集

前置要求
  • PostgreSQL 数据库连接信息
  • 可能需要目标 API 的认证凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "geEVmbXLYDSA8UGM",
  "meta": {
    "instanceId": "5ca157bf036415a321c9d29eeb986017053989bb83b5b61701e90fe3987ac8b7",
    "templateCredsSetupCompleted": true
  },
  "name": "Instagram 潜在客户生成",
  "tags": [],
  "nodes": [
    {
      "id": "5f49d3d3-5e81-4b9d-9bc4-687ee97e2e8f",
      "name": "当点击“测试工作流”时",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -256,
        0
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "9990229b-1098-4ff5-8906-c57a260f4d15",
      "name": "编辑字段",
      "type": "n8n-nodes-base.set",
      "position": [
        -32,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "8b66c6fb-0773-4c66-b088-e35fbb27fd08",
              "name": "site",
              "type": "string",
              "value": "instagram"
            },
            {
              "id": "9dddc30f-b90d-4759-81be-96161bc5dd48",
              "name": "field_of_interest",
              "type": "string",
              "value": "beauty & hair"
            },
            {
              "id": "9fba044b-013f-4ff0-8687-6a6c8954011a",
              "name": "target_country",
              "type": "string",
              "value": "USA"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "a40f44bc-efee-4c89-8fbc-77cd0d09ff3e",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        224,
        0
      ],
      "parameters": {
        "text": "=field of interest: {{ $json.field_of_interest }}\ntarget country: {{ $json.target_country }}",
        "options": {
          "systemMessage": "You are an assistant designed to generate Google search queries based on user instructions. Your sole task is to create queries following a specific format like the one below:\n\nsite:instagram.com/*/ (inurl:\"/beauty\" OR inurl:\"/hair\" OR intitle:\"beauty\" OR intitle:\"hair\") (\"England\" OR \"UK\" OR \"London\" OR \"Manchester\" OR \"Birmingham\" OR \"Liverpool\" OR \"Leeds\") (\"@gmail.com\" OR \"@yahoo.com\" OR \"@hotmail.com\" OR \"@outlook.com\" OR \"@aol.com\" OR \"@icloud.com\") -inurl:\"/p/\" -inurl:\"/reel/\" -inurl:\"/tv/\"\n\nYour output must:\n\n1. Only return the Google search query, no explanation or extra text.\n\n2. Replace the niche-related keywords (e.g., \"beauty\" or \"hair\") with the field of interest specified by the user.\n\n3. Replace the location filters (e.g., \"England\", \"UK\", \"London\") with the target country provided by the user. Add cities related to the target country as well.\n\n4. Always include the email provider filters:\n(\"@gmail.com\" OR \"@yahoo.com\" OR \"@hotmail.com\" OR \"@outlook.com\" OR \"@aol.com\" OR \"@icloud.com\")\n\n5. Always exclude media content using:\n-inurl:\"/p/\" -inurl:\"/reel/\" -inurl:\"/tv/\"\n\n6. Ensure the query remains **clean, optimized, and structurally consistent** with the original format. Do **not explain** the query — return only the **raw search string**.\n"
        },
        "promptType": "define"
      },
      "typeVersion": 1.9
    },
    {
      "id": "79b4c5f6-7fe9-46eb-932b-4d98593c2607",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        224,
        208
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "dUQjRoJSrkOznqAl",
          "name": "My OpenAi account "
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "d2eecb84-b111-401c-9fb2-91722625cb66",
      "name": "HTTP 请求",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        736,
        32
      ],
      "parameters": {
        "url": "https://api.apify.com/v2/acts/apify~google-search-scraper/run-sync-get-dataset-items?token=apify_api_YOUR_TOKEN_HERE",
        "options": {},
        "jsonBody": "={\n    \"focusOnPaidAds\": false,\n    \"forceExactMatch\": false,\n    \"includeIcons\": false,\n    \"includeUnfilteredResults\": false,\n    \"maxPagesPerQuery\": 20,\n    \"mobileResults\": false,\n    \"queries\": \"{{ $json.escapedQuery }}\",\n    \"resultsPerPage\": 100,\n    \"saveHtml\": false,\n    \"saveHtmlToKeyValueStore\": true\n} ",
        "sendBody": true,
        "specifyBody": "json"
      },
      "typeVersion": 4.2
    },
    {
      "id": "ff3a6ff0-f66f-499d-b56f-2ae8f22534ba",
      "name": "代码",
      "type": "n8n-nodes-base.code",
      "position": [
        496,
        0
      ],
      "parameters": {
        "jsCode": "// n8n Function node code\nconst inputQuery = $input.first().json.output;\n\n// Replace all \" with \\\"\nconst escapedQuery = inputQuery.replace(/\"/g, '\\\\\"');\n\n// Return as output\nreturn [\n  {\n    json: {\n      escapedQuery\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "dd29f519-c629-4302-ad17-e1a5b0555e46",
      "name": "分离输出",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        896,
        32
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "organicResults"
      },
      "typeVersion": 1
    },
    {
      "id": "32b57f66-c3cd-4a04-a787-3f7662af13c2",
      "name": "HTTP 请求",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1456,
        80
      ],
      "parameters": {
        "url": "https://api.apify.com/v2/acts/apify~instagram-scraper/run-sync-get-dataset-items?token=apify_api_YOUR_TOKEN_HERE",
        "options": {},
        "jsonBody": "={\n    \"addParentData\": false,\n    \"directUrls\": [\n        \"{{ $json.cleanedUrl }}\"\n    ],\n    \"enhanceUserSearchWithFacebookPage\": false,\n    \"isUserReelFeedURL\": false,\n    \"isUserTaggedFeedURL\": false,\n    \"resultsLimit\": 2,\n    \"resultsType\": \"details\",\n    \"searchLimit\": 1,\n    \"searchType\": \"hashtag\"\n} ",
        "sendBody": true,
        "specifyBody": "json"
      },
      "typeVersion": 4.2
    },
    {
      "id": "6e52cddd-1cf2-433f-8f78-cd1f0f2d89ad",
      "name": "代码1",
      "type": "n8n-nodes-base.code",
      "position": [
        1312,
        80
      ],
      "parameters": {
        "jsCode": "// n8n Function node code\nconst inputUrl = $input.first().json.url;\n\n// Remove trailing slash if present\nconst cleanedUrl = inputUrl.replace(/\\/$/, \"\");\n\nreturn [\n  {\n    json: {\n      cleanedUrl\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "28aaf56d-ee27-4a81-9cd7-b0e43d13aeb9",
      "name": "信息提取器",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "position": [
        1600,
        80
      ],
      "parameters": {
        "text": "={{ $json.biography }}",
        "options": {
          "systemPromptTemplate": "You are an expert extraction algorithm. Extract relevant information from the given web scraped text data and present it in JSON format with the attribute Email . If email attribute is not found in the text, assign them the value \"N/A\". Always extract email address in small hand."
        },
        "schemaType": "manual",
        "inputSchema": "{\n\t\"type\": \"array\",\n\t\"properties\": {\n\t\t\"Email\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"format\": \"email\"\n\t\t}\n\t}\n}"
      },
      "typeVersion": 1
    },
    {
      "id": "f2a03fb3-9171-482e-b078-05a5dff93e6a",
      "name": "OpenAI 聊天模型1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1600,
        304
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-3.5-turbo",
          "cachedResultName": "gpt-3.5-turbo"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "dUQjRoJSrkOznqAl",
          "name": "My OpenAi account "
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "9d1fbc5b-538a-4d82-a897-00a03ce4d5cc",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1152,
        32
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "067b1f22-eb31-4573-80e1-47fac5bddb7b",
      "name": "Postgres",
      "type": "n8n-nodes-base.postgres",
      "position": [
        2032,
        80
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "Instagram_Leads_Beauty&Hair",
          "cachedResultName": "Instagram_Leads_Beauty&Hair"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "email": "={{ $('Filter').item.json.output[0].Email }}",
            "user_name": "={{ $('HTTP Request1').item.json.username }}",
            "account_link": "={{ $('HTTP Request1').item.json.inputUrl }}",
            "follower_count": "={{ $('HTTP Request1').item.json.followsCount }}",
            "target_country": "={{ $('Edit Fields').item.json.target_country }}",
            "field_of_interest": "={{ $('Edit Fields').item.json.field_of_interest }}"
          },
          "schema": [
            {
              "id": "user_name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "user_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "follower_count",
              "type": "number",
              "display": true,
              "required": true,
              "displayName": "follower_count",
              "defaultMatch": false,
              "canBeUsedToMatch": false
            },
            {
              "id": "account_link",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "account_link",
              "defaultMatch": false,
              "canBeUsedToMatch": false
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": false
            },
            {
              "id": "target_country",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "target_country",
              "defaultMatch": false,
              "canBeUsedToMatch": false
            },
            {
              "id": "field_of_interest",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "field_of_interest",
              "defaultMatch": false,
              "canBeUsedToMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "user_name"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "upsert"
      },
      "credentials": {
        "postgres": {
          "id": "sZAvcVeX17fuVXQz",
          "name": "Postgres account"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "c8d53921-24d1-4f79-ab40-2f5794f0f057",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -112,
        -128
      ],
      "parameters": {
        "color": 5,
        "width": 256,
        "height": 304,
        "content": "## 指定我们的目标细分领域"
      },
      "typeVersion": 1
    },
    {
      "id": "a466c89c-8766-4927-871c-474a67a42265",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        176,
        -128
      ],
      "parameters": {
        "width": 464,
        "height": 464,
        "content": "## 生成自定义优化的搜索引擎查询以查找 Instagram 账号"
      },
      "typeVersion": 1
    },
    {
      "id": "8d2a5c18-c22b-4773-8890-12fa1e0b7913",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        672,
        -128
      ],
      "parameters": {
        "color": 3,
        "width": 368,
        "height": 336,
        "content": "## 使用 Apify API 提取搜索结果"
      },
      "typeVersion": 1
    },
    {
      "id": "6d5711e0-b5d3-43ee-b1f4-b8db6c853d7d",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1072,
        -128
      ],
      "parameters": {
        "color": 4,
        "width": 848,
        "height": 560,
        "content": "## 遍历每个账号并从用户简介中提取潜在客户"
      },
      "typeVersion": 1
    },
    {
      "id": "0c298e44-251f-4718-9f58-ba8904cb2708",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1952,
        -32
      ],
      "parameters": {
        "color": 6,
        "width": 256,
        "height": 272,
        "content": "## 将潜在客户存储到 PostgreSQL"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "cd76a0c4-c864-4bb3-906f-57bfb43d2a9e",
  "connections": {
    "Code": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code1": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Postgres": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "Information Extractor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Code1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Information Extractor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Information Extractor": {
      "main": [
        [
          {
            "node": "Postgres",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 潜在客户开发, AI RAG 检索增强

需要付费吗?

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

工作流信息
难度等级
高级
节点数量18
分类2
节点类型11
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

外部链接
在 n8n.io 查看

分享此工作流