{ "name": "Parapharmacy Scraper", "nodes": [ { "parameters": { "rule": { "interval": [ { "field": "cronExpression", "expression": "0 2 */3 * *" } ] } }, "id": "schedule-trigger", "name": "Schedule (Every 3 days at 2am)", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1.2, "position": [220, 300] }, { "parameters": { "values": { "string": [ { "name": "queries", "value": "crema hidratante cara,protector solar,leche corporal,champú bebé,aceite bebé,crema pañal,vitaminas bebé,formula lactea" } ] }, "options": {} }, "id": "set-queries", "name": "Set Search Queries", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [440, 300] }, { "parameters": { "fieldToSplitOut": "queries", "options": {} }, "id": "split-queries", "name": "Split Queries", "type": "n8n-nodes-base.splitOut", "typeVersion": 1, "position": [660, 300] }, { "parameters": { "method": "GET", "url": "https://www.promofarma.com/es/search?q={{ encodeURIComponent($json.queries) }}", "options": { "timeout": 30000 } }, "id": "scrape-promofarma", "name": "Scrape Promofarma", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [880, 200] }, { "parameters": { "jsCode": "// Extract products from Promofarma HTML\nconst html = $input.first().json.data;\nconst products = [];\n\n// Simple regex extraction (adjust selectors based on actual HTML)\nconst productRegex = /
]*>([\\s\\S]*?)<\\/div>/gi;\nconst nameRegex = /]*>([^<]+)<\\/h3>/i;\nconst priceRegex = /class=\"price[^\"]*\"[^>]*>([^<]+)<\\/span>/i;\nconst linkRegex = /]*href=\"([^\"]+)\"[^>]*>/i;\n\nlet match;\nwhile ((match = productRegex.exec(html)) !== null) {\n const card = match[1];\n const name = nameRegex.exec(card)?.[1]?.trim();\n const price = priceRegex.exec(card)?.[1]?.trim();\n const link = linkRegex.exec(card)?.[1];\n \n if (name) {\n products.push({\n name,\n price: parseFloat(price?.replace(/[^\\d.,]/g, '').replace(',', '.')) || 0,\n source_url: link?.startsWith('http') ? link : `https://www.promofarma.com${link}`,\n source: 'promofarma',\n source_product_id: link?.match(/\\/p\\/([^/]+)/)?.[1] || Date.now().toString()\n });\n }\n}\n\nreturn products.map(p => ({ json: p }));" }, "id": "extract-promofarma", "name": "Extract Products", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [1100, 200] }, { "parameters": { "method": "POST", "url": "http://parapharmacy-api:3002/api/products/bulk", "sendBody": true, "bodyParameters": { "parameters": [] }, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ products: $input.all().map(item => item.json) }) }}", "options": {} }, "id": "send-to-api", "name": "Send to Parapharmacy API", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [1320, 200] }, { "parameters": {}, "id": "no-operation", "name": "No Op", "type": "n8n-nodes-base.noOp", "typeVersion": 1, "position": [1540, 200] } ], "connections": { "Schedule (Every 3 days at 2am)": { "main": [ [ { "node": "Set Search Queries", "type": "main", "index": 0 } ] ] }, "Set Search Queries": { "main": [ [ { "node": "Split Queries", "type": "main", "index": 0 } ] ] }, "Split Queries": { "main": [ [ { "node": "Scrape Promofarma", "type": "main", "index": 0 } ] ] }, "Scrape Promofarma": { "main": [ [ { "node": "Extract Products", "type": "main", "index": 0 } ] ] }, "Extract Products": { "main": [ [ { "node": "Send to Parapharmacy API", "type": "main", "index": 0 } ] ] }, "Send to Parapharmacy API": { "main": [ [ { "node": "No Op", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": { "executionOrder": "v1" }, "versionId": "1" }