8
n8n 中文网amn8n.com

🏤 欧盟事件抓取与 Google Sheets

高级

这是一个AI, Marketing领域的自动化工作流,包含 20 个节点。主要使用 If, Set, Code, Html, Wait 等节点,结合人工智能技术实现智能自动化。 🏤 使用 Google Sheets 抓取欧盟事件

前置要求
  • 可能需要目标 API 的认证凭证
  • Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "",
  "meta": {
    "instanceId": "",
    "templateCredsSetupCompleted": true
  },
  "name": "🏤 Scrapping of European Union Events with Google Sheets",
  "tags": [],
  "nodes": [
    {
      "id": "f55e2060-7582-43be-96c2-285a5c8b933a",
      "name": "Initiate Static Data",
      "type": "n8n-nodes-base.code",
      "notes": "You only need to run the initialization step once per workflow, regardless of the number of Telegram chat IDs. The initialization creates the telegramStates object within the global static data of the workflow. Once that object exists, the workflow will use it to store the state for any chat ID.",
      "position": [
        -560,
        -340
      ],
      "parameters": {
        "jsCode": "let workflowStaticData = $getWorkflowStaticData('global');\nworkflowStaticData.page = -1;\nworkflowStaticData.results = [];\nreturn workflowStaticData;\n"
      },
      "notesInFlow": false,
      "typeVersion": 2
    },
    {
      "id": "6e6e6777-f491-48a9-9cbf-7ab02c94158d",
      "name": "Store Tables",
      "type": "n8n-nodes-base.code",
      "position": [
        500,
        -380
      ],
      "parameters": {
        "jsCode": "const workflowStaticData = $getWorkflowStaticData('global');\n\nif (!Array.isArray(workflowStaticData.results)) {\n  workflowStaticData.results = [];\n}\n\nconst newEvents = $input.all().map(item => item.json);\n\nworkflowStaticData.results.push(...newEvents);\n\nreturn [\n  {\n    json: {\n      addedThisRound: newEvents.length,\n      totalStored: workflowStaticData.results.length\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "1c82a460-6209-44a5-9e30-17de23062ed6",
      "name": "page+1",
      "type": "n8n-nodes-base.code",
      "position": [
        -560,
        -180
      ],
      "parameters": {
        "jsCode": "let workflowStaticData = $getWorkflowStaticData('global');\n\nif (!workflowStaticData.page) {\n    workflowStaticData.page = 0; \n}\nworkflowStaticData.page += 1\n\nreturn {\n  'page': workflowStaticData.page\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "75cc2de2-5cce-4b77-8e0a-9e7387c8dbd6",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        500,
        -180
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "315735a1-8c34-4c9f-a4ff-a6e9bd715d13",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $('page+1').item.json.page }}",
              "rightValue": "={{ 3 }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "d6f69a3c-611c-403b-9e52-636694c7d579",
      "name": "Extract Blocks",
      "type": "n8n-nodes-base.html",
      "position": [
        -160,
        -180
      ],
      "parameters": {
        "options": {},
        "operation": "extractHtmlContent",
        "extractionValues": {
          "values": [
            {
              "key": "blocks",
              "cssSelector": "article.ecl-content-item",
              "returnArray": true,
              "returnValue": "html"
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 1.2
    },
    {
      "id": "90fb346b-d39c-4941-b6c5-b314f2401b79",
      "name": "Query EU Website",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -340,
        -180
      ],
      "parameters": {
        "url": "=https://european-union.europa.eu/news-and-events/events_en?page={{ $json.page }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "9237332c-78f0-43ef-af2e-88e1dc3dc219",
      "name": "Load Old Records",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -360,
        340
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "",
          "name": ""
        }
      },
      "notesInFlow": true,
      "typeVersion": 4.6
    },
    {
      "id": "6ef271ab-da5b-4bf0-a83d-64f323382a57",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -140,
        340
      ],
      "parameters": {
        "options": {},
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "renameField": true,
              "outputFieldName": "events",
              "fieldToAggregate": "event_name"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "83114ae9-badf-48aa-82a1-0704c04cec6a",
      "name": "Events Already Existing?",
      "type": "n8n-nodes-base.if",
      "position": [
        440,
        340
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "b69cc214-26d5-4a38-aee0-68d4f556c87a",
              "operator": {
                "type": "array",
                "operation": "contains",
                "rightType": "any"
              },
              "leftValue": "={{ $json.events }}",
              "rightValue": "={{ $json.event_name }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "ce6a8ae0-d480-45ab-b25e-3a5de3f2642b",
      "name": "15 sec",
      "type": "n8n-nodes-base.wait",
      "position": [
        760,
        -100
      ],
      "webhookId": "77ab0eb9-d29a-47ea-a076-35930247e9bb",
      "parameters": {
        "amount": 15
      },
      "typeVersion": 1.1
    },
    {
      "id": "6e9050c2-f24d-4400-911e-1f402ef0074b",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -820,
        -580
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 680,
        "content": "### 1. Workflow Trigger with Cron Job\nThe workflow is triggered every morning at 08:30 am (local time). It starts with the initialization of variables that will store **page number** and **events informations**.\n\n#### How to setup?\n- Select the time you want to set it up\n"
      },
      "typeVersion": 1
    },
    {
      "id": "18485d04-a947-4828-a46a-9101730d3a90",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -800,
        -240
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "ec41e0ba-b2fd-4f2c-833e-faba7b480062",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -400,
        -580
      ],
      "parameters": {
        "color": 7,
        "width": 1340,
        "height": 680,
        "content": "### 2. Scrapping and Parsing of Events blocks\nThis starts with the HTTP node collecting HTML code that is parsed to extract Event description, link, date and location.\n#### How to setup?\n- Set up the number of pages to scrape: fixed at 5 pages (default)\n- Set up the waiting time between two pages scrapped to avoid overloading the server"
      },
      "typeVersion": 1
    },
    {
      "id": "acbb53da-6068-4452-9b9c-289eb7c5e4c0",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -400,
        120
      ],
      "parameters": {
        "color": 7,
        "width": 580,
        "height": 500,
        "content": "### 3. Load events recorded in the Google Sheet\nLoading the events **already scrapped** to avoid duplicates.\n#### How to setup?\n1. Input of your **Google Sheet** credentials\n2. Select the folder and file where the events are stored\n3. Map the fields: **event_name, event_link, day, month, year\tevent_type, event_location**\n[Learn more about the Google Sheet Node](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.googlesheets)\n\n "
      },
      "typeVersion": 1
    },
    {
      "id": "05fe99bd-37c6-4d4c-b376-9328bae44ef8",
      "name": "Collect Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        300,
        -180
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "c446f4e4-380d-488b-af58-49d10d86b9ef",
              "name": "event_name",
              "type": "string",
              "value": "={{ $json.event_name }}"
            },
            {
              "id": "d96c9c62-ce40-48bd-96eb-8365de6b2a0e",
              "name": "event_link",
              "type": "string",
              "value": "={{ $json.event_link }}"
            },
            {
              "id": "f7bfa3be-6cb4-4577-8047-ca6c8f299b3c",
              "name": "day",
              "type": "string",
              "value": "={{ $json.day }}"
            },
            {
              "id": "cc6e4317-d685-436b-bccf-90d577a35aa1",
              "name": "month",
              "type": "string",
              "value": "={{ $json.month_1 || $json.month_2 }}"
            },
            {
              "id": "88f3ab71-6a9a-4e14-9f85-070637bc8a67",
              "name": "year",
              "type": "string",
              "value": "={{ $json.year }}"
            },
            {
              "id": "7e9247e5-350c-4813-96cc-d6e849324f55",
              "name": "event_type",
              "type": "string",
              "value": "={{ $json.event_type }}"
            },
            {
              "id": "d2bb0c0d-4d3b-49c8-846f-857a29063701",
              "name": "event_location",
              "type": "string",
              "value": "={{ $json.event_location }}"
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 3.4
    },
    {
      "id": "24938049-bc25-4bec-8c99-9feb5c00a68e",
      "name": "Parse Information",
      "type": "n8n-nodes-base.html",
      "position": [
        60,
        -180
      ],
      "parameters": {
        "options": {},
        "operation": "extractHtmlContent",
        "dataPropertyName": "blocks",
        "extractionValues": {
          "values": [
            {
              "key": "event_name",
              "cssSelector": "div.ecl-content-block__title a"
            },
            {
              "key": "event_link",
              "attribute": "href",
              "cssSelector": "div.ecl-content-block__title a",
              "returnValue": "attribute"
            },
            {
              "key": "day",
              "cssSelector": "span.ecl-date-block__day"
            },
            {
              "key": "month_1",
              "attribute": "title",
              "cssSelector": "abbr.ecl-date-block__month",
              "returnValue": "attribute"
            },
            {
              "key": "year",
              "cssSelector": "span.ecl-date-block__year"
            },
            {
              "key": "event_type",
              "cssSelector": "li.ecl-content-block__primary-meta-item"
            },
            {
              "key": "event_location",
              "cssSelector": ".ecl-content-block__description li"
            },
            {
              "key": "month_2",
              "cssSelector": "span.ecl-date-block__month"
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 1.2
    },
    {
      "id": "b676bd86-281a-46a9-a4bc-9b76c70e0b9a",
      "name": "Combine New + Old Records",
      "type": "n8n-nodes-base.merge",
      "position": [
        240,
        340
      ],
      "parameters": {
        "mode": "combineBySql"
      },
      "notesInFlow": true,
      "typeVersion": 3
    },
    {
      "id": "bdc18887-1a2c-4750-b1a0-2a0397cd3fa5",
      "name": "Store New Records",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        700,
        360
      ],
      "parameters": {
        "columns": {
          "value": {
            "day": "={{ $json.day }}",
            "year": "={{ $json.year }}",
            "month": "={{ $json.month }}",
            "event_link": "={{ $json.event_link }}",
            "event_name": "={{ $json.event_name }}",
            "event_type": "={{ $json.event_type }}",
            "event_location": "={{ $json.event_location }}"
          },
          "schema": [
            {
              "id": "event_name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "event_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "event_link",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "event_link",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "day",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "day",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "month",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "month",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "year",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "year",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "event_type",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "event_type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "event_location",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "event_location",
              "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": ""
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "",
          "name": ""
        }
      },
      "notesInFlow": true,
      "typeVersion": 4.6
    },
    {
      "id": "07f6e260-55d6-4838-9a7f-baea3fe4d7d4",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        200,
        120
      ],
      "parameters": {
        "color": 7,
        "width": 740,
        "height": 400,
        "content": "### 4. Record New Events in the Google Sheet\nRecording of new events in the google sheet.\n#### How to setup?\n1. Input of your **Google Sheet** credentials\n2. Select the folder and file where the events are stored\n3. Map the fields: **Reference Number**. **Committee**, **Rapporteur**, **Title/Description**, **PDF Link**\n[Learn more about the Google Sheet Node](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.googlesheets)\n\n "
      },
      "typeVersion": 1
    },
    {
      "id": "55d5f303-232d-499a-86c5-1959136f66d2",
      "name": "Return Lines Scrapped",
      "type": "n8n-nodes-base.code",
      "position": [
        -260,
        480
      ],
      "parameters": {
        "jsCode": "const workflowStaticData = $getWorkflowStaticData('global');\n\nif (!Array.isArray(workflowStaticData.results)) {\n  return [];\n}\n\nreturn workflowStaticData.results.map(result => ({ json: result }));\n"
      },
      "typeVersion": 2
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "364d5f7e-11de-49fa-929e-edbd723a92e0",
  "connections": {
    "75cc2de2-5cce-4b77-8e0a-9e7387c8dbd6": {
      "main": [
        [],
        [
          {
            "node": "ce6a8ae0-d480-45ab-b25e-3a5de3f2642b",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ce6a8ae0-d480-45ab-b25e-3a5de3f2642b": {
      "main": [
        [
          {
            "node": "1c82a460-6209-44a5-9e30-17de23062ed6",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "1c82a460-6209-44a5-9e30-17de23062ed6": {
      "main": [
        [
          {
            "node": "90fb346b-d39c-4941-b6c5-b314f2401b79",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "6ef271ab-da5b-4bf0-a83d-64f323382a57": {
      "main": [
        [
          {
            "node": "b676bd86-281a-46a9-a4bc-9b76c70e0b9a",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "6e6e6777-f491-48a9-9cbf-7ab02c94158d": {
      "main": [
        []
      ]
    },
    "05fe99bd-37c6-4d4c-b376-9328bae44ef8": {
      "main": [
        [
          {
            "node": "6e6e6777-f491-48a9-9cbf-7ab02c94158d",
            "type": "main",
            "index": 0
          },
          {
            "node": "75cc2de2-5cce-4b77-8e0a-9e7387c8dbd6",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "d6f69a3c-611c-403b-9e52-636694c7d579": {
      "main": [
        [
          {
            "node": "24938049-bc25-4bec-8c99-9feb5c00a68e",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "9237332c-78f0-43ef-af2e-88e1dc3dc219": {
      "main": [
        [
          {
            "node": "6ef271ab-da5b-4bf0-a83d-64f323382a57",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "90fb346b-d39c-4941-b6c5-b314f2401b79": {
      "main": [
        [
          {
            "node": "d6f69a3c-611c-403b-9e52-636694c7d579",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "18485d04-a947-4828-a46a-9101730d3a90": {
      "main": [
        [
          {
            "node": "1c82a460-6209-44a5-9e30-17de23062ed6",
            "type": "main",
            "index": 0
          },
          {
            "node": "f55e2060-7582-43be-96c2-285a5c8b933a",
            "type": "main",
            "index": 0
          },
          {
            "node": "9237332c-78f0-43ef-af2e-88e1dc3dc219",
            "type": "main",
            "index": 0
          },
          {
            "node": "55d5f303-232d-499a-86c5-1959136f66d2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "24938049-bc25-4bec-8c99-9feb5c00a68e": {
      "main": [
        [
          {
            "node": "05fe99bd-37c6-4d4c-b376-9328bae44ef8",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "55d5f303-232d-499a-86c5-1959136f66d2": {
      "main": [
        [
          {
            "node": "b676bd86-281a-46a9-a4bc-9b76c70e0b9a",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "83114ae9-badf-48aa-82a1-0704c04cec6a": {
      "main": [
        [],
        [
          {
            "node": "bdc18887-1a2c-4750-b1a0-2a0397cd3fa5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "b676bd86-281a-46a9-a4bc-9b76c70e0b9a": {
      "main": [
        [
          {
            "node": "83114ae9-badf-48aa-82a1-0704c04cec6a",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 人工智能, 营销

需要付费吗?

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

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

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

作者
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 查看

分享此工作流

分类

分类: 34