8
n8n 中文网amn8n.com

🧑‍🦯使用GPT-4o和Google表格改进网站可访问性

中级

这是一个Product, AI, Marketing领域的自动化工作流,包含 14 个节点。主要使用 If, Set, Code, Limit, HttpRequest 等节点,结合人工智能技术实现智能自动化。 🧑‍🦯使用GPT-4o和Google表格改进网站可访问性

前置要求
  • 可能需要目标 API 的认证凭证
  • Google Sheets API 凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "=",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "bdc398f0-a882-4fbe-ac37-7ca7e15a1081",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2080,
        -200
      ],
      "parameters": {
        "width": 460,
        "height": 340,
        "content": "![教程](https://www.samirsaci.com/content/images/2025/04/temp-8.png)"
      },
      "typeVersion": 1
    },
    {
      "id": "d132a584-770e-438c-bd98-28a9c1afa780",
      "name": "当点击\"测试工作流\"时",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        1000,
        120
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "d51eec9d-a177-4f5e-89e5-c73b6109f5ce",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        2100,
        640
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "41da741b-1c1d-4d41-9a96-85cadacd1c8e",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1000,
        -200
      ],
      "parameters": {
        "color": 7,
        "width": 1040,
        "height": 460,
        "content": "### 1. 第一个模块:审核页面以提取所有图片及其对应的替代文本"
      },
      "typeVersion": 1
    },
    {
      "id": "e7a269cd-a2da-4ea9-9ec8-c023c45b9e96",
      "name": "页面链接",
      "type": "n8n-nodes-base.set",
      "position": [
        1200,
        120
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "e69e5e68-5cd1-4f81-a940-2e5202d5589b",
              "name": "url",
              "type": "string",
              "value": "https://www.samirsaci.com/sustainable-business-strategy-with-data-analytics/"
            },
            {
              "id": "8839ac43-5d6a-4656-b555-714f836fc687",
              "name": "baseUrl",
              "type": "string",
              "value": "https://www.samirsaci.com"
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 3.4
    },
    {
      "id": "6e6b7801-1f4c-4d00-826d-184dff58cee1",
      "name": "下载结果",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1440,
        640
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "=",
          "value": "gid=0",
          "cachedResultUrl": "=",
          "cachedResultName": "="
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "=",
          "cachedResultUrl": "=",
          "cachedResultName": "="
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "1a137755-3f14-4881-93a5-db7f8678fa0d",
      "name": "替代文本长度 < 50",
      "type": "n8n-nodes-base.if",
      "position": [
        1660,
        640
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "a3b0ca70-0496-4966-94fd-f2927ce02ba9",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{ $json.altLength }}",
              "rightValue": 100
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "60ea3935-313e-4d16-a8b8-a2fe7da8df82",
      "name": "限制记录",
      "type": "n8n-nodes-base.limit",
      "position": [
        1880,
        560
      ],
      "parameters": {
        "maxItems": 5
      },
      "typeVersion": 1
    },
    {
      "id": "5785deb6-1bf4-40a6-b556-42aad4c01c83",
      "name": "生成替代文本",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        2320,
        560
      ],
      "parameters": {
        "text": "Please generate the alternative text (alt text) for this image under 150 characters.\t",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-2024-05-13",
          "cachedResultName": "GPT-4O-2024-05-13"
        },
        "options": {
          "maxTokens": 150
        },
        "resource": "image",
        "imageUrls": "={{ $('altLength < 50').item.json.src }}",
        "operation": "analyze"
      },
      "notesInFlow": true,
      "typeVersion": 1.8
    },
    {
      "id": "86051a7f-e91a-4913-9c19-772673ff6306",
      "name": "更新结果",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2540,
        640
      ],
      "parameters": {
        "columns": {
          "value": {
            "page": "=",
            "index": "={{ $('Loop Over Items').item.json.index }}",
            "newAlt": "={{ $json.content }}"
          },
          "schema": [
            {
              "id": "index",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "index",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "page",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "page",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "src",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "src",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "alt",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "alt",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "altLength",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "altLength",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "newAlt",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "newAlt",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "string",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "index"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "=",
          "cachedResultName": "="
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "=",
          "cachedResultUrl": "=",
          "cachedResultName": "="
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "b1ab97f7-a89e-40c8-ada3-22fcc6da2dcd",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1000,
        320
      ],
      "parameters": {
        "color": 7,
        "width": 1920,
        "height": 520,
        "content": "### 2. 第二个模块:为替代文本长度 < 50 的图片生成替代文本"
      },
      "typeVersion": 1
    },
    {
      "id": "c1bf1dcf-6789-43dd-9f15-29895c30fd23",
      "name": "存储结果",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1860,
        120
      ],
      "parameters": {
        "columns": {
          "value": {
            "alt": "={{ $json.alt }}",
            "src": "={{ $json.src }}",
            "page": "={{ $('Page Link').item.json.url }}",
            "index": "={{ $json.index }}",
            "altLength": "={{ $json.altLength }}"
          },
          "schema": [
            {
              "id": "index",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "index",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "page",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "page",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "src",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "src",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "alt",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "alt",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "altLength",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "altLength",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "newAlt",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "newAlt",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "=",
          "cachedResultName": "="
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "=",
          "cachedResultUrl": "=",
          "cachedResultName": "="
        }
      },
      "notesInFlow": true,
      "typeVersion": 4.5
    },
    {
      "id": "fe71094e-3a22-4cda-90ad-4174258a9086",
      "name": "下载 HTML",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1420,
        120
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "405fe4cf-5271-465c-8e2a-1f5d024228b6",
      "name": "获取带替代文本的图片 URL",
      "type": "n8n-nodes-base.code",
      "position": [
        1640,
        120
      ],
      "parameters": {
        "jsCode": "const html = $input.first().json.data;\nconst baseUrl = $('Page Link').first().json.baseUrl;\n\nconst imgTagRegex = /<img\\b[^>]*>/gi;\nconst altAttrRegex = /alt\\s*=\\s*[\"']([^\"']*)[\"']/i;\nconst srcAttrRegex = /src\\s*=\\s*[\"']([^\"']*)[\"']/i;\n\nconst imageTags = html.match(imgTagRegex) || [];\n\nconst results = imageTags.map((tag, index) => {\n  const altMatch = tag.match(altAttrRegex);\n  const srcMatch = tag.match(srcAttrRegex);\n\n  let alt = altMatch ? altMatch[1] : '[No alt text]';\n  let src = srcMatch ? srcMatch[1] : '[No src]';\n\n  // If src is relative, manually join with baseUrl\n  if (src !== '[No src]' && !src.startsWith('http')) {\n    if (baseUrl.endsWith('/') && src.startsWith('/')) {\n      src = baseUrl + src.slice(1);\n    } else if (!baseUrl.endsWith('/') && !src.startsWith('/')) {\n      src = baseUrl + '/' + src;\n    } else {\n      src = baseUrl + src;\n    }\n  }\n\n  return {\n    index: index + 1,\n    src,\n    alt,\n    altLength: alt.length,\n  };\n});\n\nreturn results.map(item => ({ json: item }));"
      },
      "typeVersion": 2
    }
  ],
  "pinData": {},
  "connections": {
    "Page Link": {
      "main": [
        [
          {
            "node": "Download HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download HTML": {
      "main": [
        [
          {
            "node": "Get Images urls with altText",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit records": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Results": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "altLength < 50": {
      "main": [
        [
          {
            "node": "Limit records",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Generate altText",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Results": {
      "main": [
        [
          {
            "node": "altLength < 50",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate altText": {
      "main": [
        [
          {
            "node": "Update Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Images urls with altText": {
      "main": [
        [
          {
            "node": "Store Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Page Link",
            "type": "main",
            "index": 0
          },
          {
            "node": "Download Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 产品, 人工智能, 营销

需要付费吗?

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

工作流信息
难度等级
中级
节点数量14
分类3
节点类型10
难度说明

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

作者
Samir Saci

Samir Saci

@samirsaci

Automation, AI and Analytics for Supply Chain & Business Optimization Helping businesses streamline operations using n8n, AI agents, and data science to enhance efficiency and sustainability. Linkedin: www.linkedin.com/in/samir-saci

外部链接
在 n8n.io 查看

分享此工作流