{
  "name": "reddit-scraper",
  "nodes": [
    {
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "targetURL"
            }
          ]
        }
      },
      "id": "2dd44f3b-aafc-4fc1-ad98-04c58ab4ecd0",
      "name": "When Executed by Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.2,
      "position": [
        -192,
        16
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://browserless:3000/function",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ {\n  \"context\": {\n    \"redditUrl\": (() => { let u = String($json.targetURL).replace(/[\"']/g, \"\").trim(); if (u.includes(\".json\")) return u; if (u.endsWith(\"/\")) u = u.slice(0, -1); return u + \".json\"; })()\n  },\n  \"code\": \"module.exports = async ({ page, context }) => { await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'); await page.setExtraHTTPHeaders({ 'Accept-Language': 'en-US,en;q=0.9' }); await page.goto('https://www.reddit.com', { waitUntil: 'networkidle2', timeout: 30000 }); await page.goto(context.redditUrl, { waitUntil: 'domcontentloaded', timeout: 30000 }); const rawText = await page.evaluate(() => document.body.innerText); return { data: JSON.parse(rawText), type: 'application/json' }; };\"\n} }}",
        "options": {}
      },
      "id": "0c267645-45ac-4ad4-941e-5c5df7c6f716",
      "name": "Scrape_Reddit_via_Browserless_JSON",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        32,
        16
      ],
      "notesInFlow": false,
      "notes": "Runs custom Puppeteer automation via Browserless. Takes targetURL from the caller, bypasses Reddit's fingerprint check by visiting reddit.com first, then fetches the .json endpoint and returns raw structured JSON. URL logic is .json-aware: a URL that already contains .json (with any query string) is used as-is; a plain /r/sub/ URL gets .json appended."
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a18004f7-2ad8-445b-b0d5-de631f279e97",
              "name": "data.children",
              "value": "={{ $json.data.children }}",
              "type": "array"
            }
          ]
        },
        "options": {}
      },
      "id": "3753967f-bb2e-4dd1-9dc5-53f97b2e9351",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        256,
        16
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "data.children",
        "options": {}
      },
      "id": "c1da0e89-6736-416f-97a3-096bf5fa8369",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        480,
        16
      ]
    }
  ],
  "connections": {
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Scrape_Reddit_via_Browserless_JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Scrape_Reddit_via_Browserless_JSON": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "versionId": "89344f11-02bd-408f-baba-d6bd18134f3c",
  "nodeGroups": [],
  "id": "knObnnQbnIHP9DAy",
  "tags": []
}