{
  "id": "fffRt3A8pcGDhAYV",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Automate Directory Scraping to Google Sheets using BrowserAct",
  "tags": [],
  "nodes": [
    {
      "id": "8ad92360-1ee6-44cb-ad18-ff1d898489b0",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -32,
        208
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "281fdee8-0b6e-4f2d-b811-7376e20c14f2",
      "name": "Run a workflow task",
      "type": "n8n-nodes-browseract-workflows.browserAct",
      "position": [
        144,
        208
      ],
      "parameters": {
        "workflowId": "56683859462521975",
        "inputParameters": {
          "parameters": [
            {
              "name": "business_category",
              "value": "dentists"
            },
            {
              "name": "city_location",
              "value": "Brooklyn"
            }
          ]
        },
        "additionalFields": {
          "saveBrowserData": false
        }
      },
      "credentials": {
        "browserActApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "35073d60-1922-4fec-a162-de41e3c3a037",
      "name": "Get details of a workflow task",
      "type": "n8n-nodes-browseract-workflows.browserAct",
      "position": [
        352,
        208
      ],
      "parameters": {
        "taskId": "={{ $json.id }}",
        "operation": "getTask",
        "maxWaitTime": 600,
        "waitForFinish": true,
        "pollingInterval": 20
      },
      "credentials": {
        "browserActApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "6efa3204-54af-4b38-95a7-9996028b6166",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        640,
        208
      ],
      "parameters": {
        "jsCode": "// Get the JSON string using the exact path provided by the user.\nconst jsonString = $input.first().json.output.string;\n\nlet parsedData;\n\n// Check if the string exists before attempting to parse\nif (!jsonString) {\n    // Return an empty array or throw an error if no string is found\n    // Throwing an error is usually better to stop the workflow if data is missing.\n    throw new Error(\"Input string is empty or missing at the specified path: $input.first().json.output.string\");\n}\n\ntry {\n    // 1. Parse the JSON string into a JavaScript array of objects\n    parsedData = JSON.parse(jsonString);\n} catch (error) {\n    // Handle JSON parsing errors (e.g., if the string is malformed)\n    throw new Error(`Failed to parse JSON string: ${error.message}`);\n}\n\n// 2. Ensure the parsed data is an array\nif (!Array.isArray(parsedData)) {\n    throw new Error('Parsed data is not an array. It cannot be split into multiple items.');\n}\n\n// 3. Map the array of objects into the n8n item format { json: object }\n// Each element in this array will be treated as a new item by n8n, achieving the split.\nconst outputItems = parsedData.map(item => ({\n    json: item,\n}));\n\n// 4. Return the new array of items\nreturn outputItems;"
      },
      "typeVersion": 2
    },
    {
      "id": "dc54c1f9-db58-48fd-92c1-45091fd18751",
      "name": "Append or update row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        944,
        208
      ],
      "parameters": {
        "columns": {
          "value": {
            "Address": "={{ $json.Location }}",
            "Category": "={{ $json.Business }}",
            "Company Name": "={{ $json.Name }}",
            "Phone Number": "={{ $json.Phone }}"
          },
          "schema": [
            {
              "id": "Company Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Company Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Category",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Category",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone Number",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Phone Number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Address",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Address",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Company Name"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 512924235,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/18sw7io0yJOTDzvcknGmjBBqtK154CLk3k0FoWJZbfI0/edit#gid=512924235",
          "cachedResultName": "Online Directory Lead Scraper (YP.com)"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "18sw7io0yJOTDzvcknGmjBBqtK154CLk3k0FoWJZbfI0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/18sw7io0yJOTDzvcknGmjBBqtK154CLk3k0FoWJZbfI0/edit?usp=drivesdk",
          "cachedResultName": "Test For BrowserAct"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "764d9961-c8f2-4b85-a30f-5953edec0645",
      "name": "Sticky Note - Intro",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        -160
      ],
      "parameters": {
        "width": 592,
        "height": 424,
        "content": "## Try It Out!\n### This n8n template helps you generate local business leads by scraping online directories and saving the results directly to a spreadsheet.\n\n### How it works\n* The workflow is triggered **manually**. You can replace the trigger with a **Cron** node to run it on a schedule for different search terms.\n* A **BrowserAct** node starts a web scraping task with specific inputs (e.g., 'dentists' in 'Brooklyn') to collect business listings.\n* A second **BrowserAct** node patiently waits for the scraping job to finish.\n* A **Code** node takes the raw scraped data (which arrives as a single text block) and correctly parses and splits it into individual items, one for each business.\n* Finally, the structured business leads are added directly to your **Google Sheet**.\n\n### Requirements\n* **BrowserAct** API account for web scraping.\n* **BrowserAct** **Online Directory Lead Scraper (YP.com)** Template.\n* **Google Sheets** credentials for saving the leads.\n\n\n### Need Help?\nJoin the [Discord](https://discord.com/invite/UpnCKd7GaU) or Visit Our [Blog](https://www.browseract.com/blog)!\n"
      },
      "typeVersion": 1
    },
    {
      "id": "708ca10f-6d70-4b8d-8a28-4e551509b05f",
      "name": "Sticky Note - How to Use",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        272
      ],
      "parameters": {
        "width": 592,
        "height": 208,
        "content": "## How to use\n\n1.  **Set up Credentials:** Add your credentials for **BrowserAct** and **Google Sheets** to the workflow.\n2.  **Customize Your Search:** In the **Run a workflow task** node, change the `business_category` and `city_location` values to find the leads you need.\n3. Make sure you have **BrowserAct** **Online Directory Lead Scraper (YP.com)** Template. Ready.\n3.  **Add WorkFlow Name:** Update the **workflow_Name** in the Run Workflow node to match your specific BrowserAct scraping workflow.\n4.  **Activate Workflow:** Manually trigger the workflow by clicking 'Execute Workflow' to test it. For automation, replace the trigger with a `Cron` node and activate the workflow."
      },
      "typeVersion": 1
    },
    {
      "id": "e66f41b8-e129-4645-a969-fad9b7094770",
      "name": "Sticky Note - Need Help",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        496
      ],
      "parameters": {
        "width": 336,
        "height": 120,
        "content": "### Need Help?\n* #### [How to Find Your BrowseAct API Key & Workflow ID](https://www.youtube.com/watch?v=pDjoZWEsZlE)\n* #### [How to Connect n8n to Browseract](https://www.youtube.com/watch?v=RoYMdJaRdcQ)\n* #### [How to Use & Customize BrowserAct Templates](https://www.youtube.com/watch?v=CPZHFUASncY)\n* #### [How to Use the BrowserAct N8N Community Node](https://youtu.be/j0Nlba2pRLU)"
      },
      "typeVersion": 1
    },
    {
      "id": "8ebf7b39-412f-42d1-b230-f5c6344c9e3e",
      "name": "Sticky Note - Scraping Stage",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        96,
        0
      ],
      "parameters": {
        "color": 5,
        "width": 416,
        "height": 168,
        "content": "### \ud83c\udf10 1. Scrape & Wait\n\n* **Run a workflow task:** This node starts your BrowserAct scraper. This is where you define what you're searching for (e.g., 'dentists' and 'Brooklyn'). You can easily change these inputs to find different types of businesses.\n\n* **Get details...:** This node pauses the workflow until the scraping is 100% complete, ensuring the next steps have all the data they need."
      },
      "typeVersion": 1
    },
    {
      "id": "6bfa6f3c-b47f-4e8f-9d2d-8b49eb52a031",
      "name": "Sticky Note - Processing Stage",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        528,
        0
      ],
      "parameters": {
        "color": 6,
        "width": 336,
        "height": 164,
        "content": "### \ud83e\uddf9 2. Parse & Split Data\n\nThis **Code** node is the most critical processing step. Scrapers often return a list of results as a single block of text (a JSON string). \n\nThis code takes that string, parses it, and transforms it into separate n8n items. This correctly prepares the data for the Google Sheets node to process one row at a time."
      },
      "typeVersion": 1
    },
    {
      "id": "290deae8-3767-4144-a54b-6eee32210336",
      "name": "Sticky Note - Output Stage",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        880,
        384
      ],
      "parameters": {
        "color": 3,
        "width": 288,
        "content": "### \ud83d\udcbe 3. Save to Google Sheets\n\nThis node takes each individual business lead and adds it as a new row in your sheet.\n\n**\ud83d\udca1 Tip:** The operation is set to `appendOrUpdate` and matches on 'Company Name'. This is a great setup to prevent creating duplicate entries if you run the workflow multiple times for the same search."
      },
      "typeVersion": 1
    },
    {
      "id": "897e4af5-b6c4-43c9-9dec-3ddf5d76aee8",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        96,
        192
      ],
      "parameters": {
        "color": 5,
        "width": 416,
        "height": 176,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "4fa7bfe9-c045-4768-9bb6-9e5331635a50",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        528,
        192
      ],
      "parameters": {
        "color": 6,
        "width": 336,
        "height": 176,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "31b49192-05ad-434b-8770-eb1bc279f607",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        880,
        192
      ],
      "parameters": {
        "color": 3,
        "width": 288,
        "height": 176,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "c36f1e00-e08c-421e-b5c2-4d9f5c5e47f8",
      "name": "Sticky Note - Need Help1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -288,
        496
      ],
      "parameters": {
        "height": 120,
        "content": "### Workflow Guidance and Showcase\n\n* #### [STOP Manual Leads! Automate Lead Gen with BrowserAct & n8n](https://www.youtube.com/watch?v=W9BHL7vok6c)"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "277b247a-08fc-41d5-8553-3f94d74b1793",
  "connections": {
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Append or update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run a workflow task": {
      "main": [
        [
          {
            "node": "Get details of a workflow task",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get details of a workflow task": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Run a workflow task",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}