{
  "nodes": [
    {
      "id": "02eb1076-060e-484d-84c4-fe2dcb3ed706",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        260,
        320
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "credential-id",
          "name": "openAiApi Credential"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "a8c0862a-6b53-414b-ac82-ccabefad2345",
      "name": "Start Scraping",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -200,
        0
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "f54199e8-8fa1-4ffa-b442-3700755d4a0a",
      "name": "Input Setup",
      "type": "n8n-nodes-base.set",
      "position": [
        20,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "c1e742bf-8bd2-4d18-9a51-dac7cfaa51fd",
              "name": "url",
              "type": "string",
              "value": "https://stackoverflow.com/users"
            },
            {
              "id": "107ffa9d-231b-4991-b362-415ec08505b7",
              "name": "format",
              "type": "string",
              "value": "scrape_as_markdown"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "1894bff8-13de-4fba-93ed-f021407d4e13",
      "name": "AI Agent: Generate Scraper Instructions",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        440,
        0
      ],
      "parameters": {
        "text": "=Scrape all users data as per the provided URL:  {{ $json.url }}",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2
    },
    {
      "id": "0f166f7a-e7ac-4d14-8171-7c1c36f18680",
      "name": "MCP Client to Scrape as HTML",
      "type": "n8n-nodes-mcp.mcpClientTool",
      "position": [
        620,
        320
      ],
      "parameters": {
        "toolName": "scrape_as_html",
        "operation": "executeTool",
        "toolParameters": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Tool_Parameters', ``, 'json') }}",
        "descriptionType": "manual",
        "toolDescription": "Scrape a single webpage URL with advanced options for content extraction and get back the results in html"
      },
      "credentials": {
        "mcpClientApi": {
          "id": "credential-id",
          "name": "mcpClientApi Credential"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "195a2e71-91c7-4947-ab5a-26e4e7b9e3d6",
      "name": "Conversation Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        460,
        320
      ],
      "parameters": {
        "sessionKey": "=Perform the web scraping for the below URL  {{ $json.url }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "c425d7fc-2207-4df6-8833-76265394f9b3",
      "name": "Format Data for Google Sheets",
      "type": "n8n-nodes-base.code",
      "position": [
        1020,
        0
      ],
      "parameters": {
        "jsCode": "// Get the array of users from the incoming item\nconst forums = items[0].json.output.forums;\n\nconst results = forums.map(user => {\n  return {\n    json: {\n      baseUrl: user.baseUrl,\n      profileUrl: user.exampleProfile,\n      name: user.selectors.name,\n      location: user.selectors.location,\n      reputation: user.selectors.reputation,\n      tags: user.selectors.tags\n    }\n  };\n});\n\nreturn results;\n"
      },
      "typeVersion": 2
    },
    {
      "id": "51380d2d-c833-4748-a9fb-376add68cc87",
      "name": "Save Leads to Google Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1240,
        0
      ],
      "parameters": {
        "columns": {
          "value": {
            "Name": "={{ $json.name }}",
            "Tags": "={{ $json.tags }}",
            "baseUrl": "={{ $json.baseUrl }}",
            "Location": "={{ $json.location }}",
            "Raputation": "={{ $json.reputation }}",
            "Profile URL": "={{ $json.profileUrl }}"
          },
          "schema": [
            {
              "id": "baseUrl",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "baseUrl",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Profile URL",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Profile URL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Location",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Location",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Raputation",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Raputation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Tags",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Tags",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "121-9GYz9uIhC-cBQaJ2Rg26paivPVDAvTE9pwgZ7MCA"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "credential-id",
          "name": "googleSheetsOAuth2Api Credential"
        }
      },
      "typeVersion": 4.6
    }
  ],
  "connections": {
    "Input Setup": {
      "main": [
        [
          {
            "node": "AI Agent: Generate Scraper Instructions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start Scraping": {
      "main": [
        [
          {
            "node": "Input Setup",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent: Generate Scraper Instructions",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Conversation Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent: Generate Scraper Instructions",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Auto-fixing Output Parser",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Auto-fixing Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent: Generate Scraper Instructions",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "MCP Client to Scrape as HTML": {
      "ai_tool": [
        [
          {
            "node": "AI Agent: Generate Scraper Instructions",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Format Data for Google Sheets": {
      "main": [
        [
          {
            "node": "Save Leads to Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent: Generate Scraper Instructions": {
      "main": [
        [
          {
            "node": "Format Data for Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}