8
n8n 中文网amn8n.com

Sitemap.xml 元数据导出至 Google Sheets(标题、元描述和 URL)

中级

这是一个Market Research, Multimodal AI领域的自动化工作流,包含 12 个节点。主要使用 Code, Wait, Merge, HttpRequest, GoogleSheets 等节点。 Sitemap.xml 元数据导出至 Google Sheets(标题、元描述和 URL)

前置要求
  • 可能需要目标 API 的认证凭证
  • Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "a6566740aec87c72f5c480f70b9db7e54a30eed99165e991cfd6834f8c7d1e9a"
  },
  "nodes": [
    {
      "id": "a34c9e89-88bc-4b65-8fb0-906d96623f24",
      "name": "在表格中追加或更新行",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1632,
        128
      ],
      "parameters": {
        "columns": {
          "value": {
            "URL": "={{ $json.loc }}",
            "Title": "={{ $json.title }}",
            "meta description": "={{ $json.description }}"
          },
          "schema": [
            {
              "id": "Title",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "meta description",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "meta description",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "URL",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "URL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "URL"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1784271309,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1M3A5XS7kASYmFAhRWRIuH5bgdU711cYCiGkxrEgiJsQ/edit#gid=1784271309",
          "cachedResultName": "Sheet4"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1M3A5XS7kASYmFAhRWRIuH5bgdU711cYCiGkxrEgiJsQ",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1M3A5XS7kASYmFAhRWRIuH5bgdU711cYCiGkxrEgiJsQ/edit?usp=drivesdk",
          "cachedResultName": "WP Adminify site data before sep 7"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "BHZiTn38wGOGTK86",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "465ed5f1-6a24-454f-8e15-b536eb5f0654",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        736,
        192
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "81163f56-f0b3-4b82-8535-e9c86f17e9af",
      "name": "点击\"执行工作流\"时",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        64,
        192
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "e79ea547-93d8-4325-ad23-5a5b58ef266e",
      "name": "获取站点地图 XML",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        288,
        192
      ],
      "parameters": {
        "url": "https://example.com/sitemap.xml",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "2e18cc0f-d3bd-4267-9beb-c790491c121f",
      "name": "拆分标题和 URL",
      "type": "n8n-nodes-base.code",
      "position": [
        512,
        192
      ],
      "parameters": {
        "jsCode": "// 1. Grab the raw XML string (adjust \"body\" vs \"data\" if needed)\nconst xml = items[0].json.body || items[0].json.data;\n\n// 2. Use a global regex to capture all <loc>…</loc> values\nconst urls = Array.from(\n  xml.matchAll(/<loc>(.*?)<\\/loc>/g),\n  match => match[1]\n);\n\n// 3. Emit one item per URL\nreturn urls.map(u => ({ json: { loc: u } }));\n"
      },
      "typeVersion": 2
    },
    {
      "id": "5e8cc53a-07d9-4f36-9136-e316262d0afd",
      "name": "获取特定链接的 HTML",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        960,
        48
      ],
      "parameters": {
        "url": "={{ $json.loc }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "25dcfa97-0ea6-42e0-b0de-ebba4d549bc2",
      "name": "获取元描述",
      "type": "n8n-nodes-base.code",
      "position": [
        1184,
        48
      ],
      "parameters": {
        "jsCode": "// 1. Read raw HTML from the HTTP Request node\nconst html = items[0].json.body || items[0].json.data;\n\n// 2. Extract <title>…</title>\nconst titleMatch = html.match(/<title>([\\s\\S]*?)<\\/title>/i);\nconst title = titleMatch ? titleMatch[1].trim() : '';\n\n// 3. Extract <meta name=\"description\" content=\"…\"/>\nconst descMatch = html.match(\n  /<meta\\b[^>]*\\bname=[\"']description[\"'][^>]*\\bcontent=[\"']([\\s\\S]*?)[\"']/i\n);\nconst description = descMatch ? descMatch[1].trim() : '';\n\n// 4. Return a single item with both fields\nreturn [\n  {\n    json: { title, description }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "cb0dccd4-1a14-4392-9b47-673086a584db",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        96,
        -400
      ],
      "parameters": {
        "width": 528,
        "height": 464,
        "content": "# 🔍 站点地图元数据导出器"
      },
      "typeVersion": 1
    },
    {
      "id": "232e416e-ba6d-488e-9805-95e51602beb4",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        864,
        -512
      ],
      "parameters": {
        "width": 624,
        "height": 464,
        "content": "# ⚙️ 需要配置"
      },
      "typeVersion": 1
    },
    {
      "id": "28eb6dfd-2bc3-48ab-a9ac-e325062d8913",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1792,
        -224
      ],
      "parameters": {
        "width": 400,
        "height": 336,
        "content": "# ⏸️ 速率限制"
      },
      "typeVersion": 1
    },
    {
      "id": "54d6ad61-aa54-433a-8fba-2824168d9c05",
      "name": "等待",
      "type": "n8n-nodes-base.wait",
      "position": [
        1856,
        192
      ],
      "webhookId": "6de7240c-a5e9-40ac-a371-f63db7cd90a3",
      "parameters": {
        "amount": 2
      },
      "typeVersion": 1.1
    },
    {
      "id": "7a23c4c2-06d7-45d9-b4d2-99310fe67915",
      "name": "将元描述与标题和 URL 合并",
      "type": "n8n-nodes-base.merge",
      "position": [
        1408,
        128
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.2
    }
  ],
  "pinData": {},
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Sitemap XML": {
      "main": [
        [
          {
            "node": "Split the title and url",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Get specific link html",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge Meta Description with Title and URL",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Get specific link html": {
      "main": [
        [
          {
            "node": "Get the meta description",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split the title and url": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get the meta description": {
      "main": [
        [
          {
            "node": "Merge Meta Description with Title and URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append or update row in sheet": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "Get Sitemap XML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Meta Description with Title and URL": {
      "main": [
        [
          {
            "node": "Append or update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

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

需要付费吗?

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

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

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

外部链接
在 n8n.io 查看

分享此工作流