{
  "version": "1.0.0",
  "exported_at": "2026-06-01T00:00:00.000Z",
  "project": {
    "name": "Pagesjaunesca Business Info Scraper",
    "description": "Scrapes PagesJaunes.ca business search results for the default query Restaurants; Montreal QC. Exports business name, location, description, category/type, telephone, website redirect URL, and detail URL. Pagination is implemented by incrementing the /search/si/{page}/ URL after each extraction and looping until no listing rows are found. Phone extraction is best-effort because PagesJaunes may hide/reveal phone numbers dynamically.",
    "color": "bg-[#ffcd00]",
    "template_id": "ai-generated"
  },
  "blocks": [
    {
      "block_id": "set-window-size-1",
      "block_type": "process",
      "title": "Set Window Size",
      "description": "Set browser viewport size",
      "position_x": 120,
      "position_y": 220,
      "config": {
        "width": 1920,
        "height": 1080,
        "color": "bg-[#4589ff]"
      }
    },
    {
      "block_id": "navigate-1",
      "block_type": "process",
      "title": "Navigate",
      "description": "Go to a URL",
      "position_x": 456,
      "position_y": 220,
      "config": {
        "url": "https://www.pagesjaunes.ca/search/si/1/Restaurants/Montreal+QC",
        "color": "bg-[#4589ff]",
        "tags": [
          "pagesjaunes",
          "search-results"
        ]
      }
    },
    {
      "block_id": "wait-for-page-load-1",
      "block_type": "process",
      "title": "Wait for Page Load",
      "description": "Wait for page to finish loading",
      "position_x": 792,
      "position_y": 220,
      "config": {
        "timeout": 30,
        "color": "bg-[#08bdba]"
      }
    },
    {
      "block_id": "inject-javascript-1",
      "block_type": "process",
      "title": "Inject JavaScript",
      "description": "Execute custom JavaScript",
      "position_x": 1128,
      "position_y": 220,
      "config": {
        "jsCode": "(() => { const selectors = ['button[id*=\"accept\" i]', 'button[class*=\"accept\" i]', '[class*=\"consent\" i] button', '#onetrust-accept-btn-handler']; for (const selector of selectors) { const el = document.querySelector(selector); if (el && el.offsetParent !== null) { el.click(); return 'cookie/consent clicked: ' + selector; } } return 'no visible cookie banner'; })()",
        "waitForCompletion": true,
        "timeout": 10,
        "color": "bg-[#a56eff]"
      }
    },
    {
      "block_id": "sleep-1",
      "block_type": "process",
      "title": "Sleep",
      "description": "Wait for specified time",
      "position_x": 1464,
      "position_y": 220,
      "config": {
        "duration": 1,
        "color": "bg-[#08bdba]"
      }
    },
    {
      "block_id": "wait-for-element-1",
      "block_type": "process",
      "title": "Wait for Element",
      "description": "Wait until element appears",
      "position_x": 1800,
      "position_y": 220,
      "config": {
        "selector": "div.listing[data-listing-id], div.listing",
        "timeout": 30,
        "visible": true,
        "color": "bg-[#08bdba]"
      }
    },
    {
      "block_id": "inject-javascript-3",
      "block_type": "process",
      "title": "Inject JavaScript",
      "description": "Execute custom JavaScript",
      "position_x": 2136,
      "position_y": 220,
      "config": {
        "jsCode": "(() => { const rows = Array.from(document.querySelectorAll('div.listing[data-listing-id], div.listing')); let clicked = 0; rows.forEach(row => { const controls = Array.from(row.querySelectorAll('a.jsMlrMenu, .mlr__item--phone a, a[data-analytics-placeholder*=\"phone\" i], a[data-analytics-placeholder*=\"téléphone\" i], a[data-analytics-placeholder*=\"telephone\" i], a[data-analytics-placeholder*=\"revealphonenumber\" i], button[class*=\"phone\" i], a[class*=\"phone\" i]')); controls.forEach(el => { const text = (el.textContent || '').trim(); const href = el.getAttribute('href') || ''; const blob = [text, el.className || '', el.getAttribute('data-analytics-placeholder') || '', el.getAttribute('aria-label') || '', el.getAttribute('title') || ''].join(' '); if ((href === '#' || href === '' || href.startsWith('javascript:')) && /phone|téléphone|telephone|appel|call|reveal/i.test(blob)) { try { el.scrollIntoView({ block: 'center', inline: 'nearest' }); } catch (e) {} try { el.click(); clicked++; } catch (e) {} } }); }); return 'safe phone reveal controls clicked: ' + clicked; })()",
        "waitForCompletion": true,
        "timeout": 10,
        "color": "bg-[#a56eff]"
      }
    },
    {
      "block_id": "sleep-3",
      "block_type": "process",
      "title": "Sleep",
      "description": "Wait for specified time",
      "position_x": 2472,
      "position_y": 220,
      "config": {
        "duration": 3,
        "color": "bg-[#08bdba]"
      }
    },
    {
      "block_id": "structured-export-1",
      "block_type": "process",
      "title": "Structured Export",
      "description": "Export data with custom columns",
      "position_x": 2808,
      "position_y": 220,
      "config": {
        "rowSelector": "div.listing[data-listing-id], div.listing",
        "fileName": "pagesjaunes_ca_info_scraper.csv",
        "saveLocation": "C:\\Users\\theskd\\Documents\\UScraper\\templates",
        "includeHeaders": true,
        "fileMode": "append",
        "color": "bg-[#42be65]",
        "columns": [
          {
            "name": "nom_du_magasin",
            "selector": "(() => { const q = s => ROW.querySelector(s); let text = (q('.listing__name a, .listing__name--link, h3 a, h2 a, [itemprop=\"name\"]')?.textContent || '').replace(/\\s+/g, ' ').trim(); text = text.replace(/^\\s*\\d+\\s+/, '').trim(); return text; })()",
            "attribute": "text",
            "isJs": true
          },
          {
            "name": "location",
            "selector": "(() => { const q = s => ROW.querySelector(s); let text = (q('.listing__address--full, .listing__address, [itemprop=\"address\"], .address')?.textContent || '').replace(/\\s+/g, ' ').trim(); text = text.replace(/\\bItinéraire\\b/gi, '').replace(/\\s+/g, ' ').trim(); return text; })()",
            "attribute": "text",
            "isJs": true
          },
          {
            "name": "avis_des_magasins",
            "selector": "(() => { const q = s => ROW.querySelector(s); let text = (q('.listing__details__teaser, .listing__description, .jsTeaser, [itemprop=\"description\"]')?.textContent || '').replace(/\\s+/g, ' ').trim(); text = text.replace(/\\s*plus\\.\\.\\.\\s*Plus de texte\\s*/gi, ' ').replace(/\\s*Plus de texte\\s*/gi, ' ').replace(/\\s*plus\\.\\.\\.\\s*/gi, ' ').replace(/\\s+/g, ' ').trim(); return text; })()",
            "attribute": "text",
            "isJs": true
          },
          {
            "name": "type_domaine",
            "selector": "(() => { const clean = t => t.replace(/\\s+/g, ' ').replace(/Plus…|Plus\\.\\.\\.|Plus/gi, '').trim(); const items = Array.from(ROW.querySelectorAll('.listing__headings a, .listing__categories a, [class*=\"heading\"] a, [class*=\"category\"] a')).map(el => clean(el.textContent || '')).filter(Boolean); if (items.length) return Array.from(new Set(items)).join(', '); const text = ROW.querySelector('.listing__headings, .listing__categories, [class*=\"heading\"], [class*=\"category\"]')?.textContent || ''; return clean(text); })()",
            "attribute": "text",
            "isJs": true
          },
          {
            "name": "telephone",
            "selector": "(() => { const phoneRe = /(?:\\+?1[\\s.\\-]*)?\\(?\\d{3}\\)?[\\s.\\-]*\\d{3}[\\s.\\-]*\\d{4}/; const normalize = v => (v || '').replace(/\\\\u002D/g, '-').replace(/\\\\u002F/g, '/').replace(/&nbsp;/g, ' ').replace(/&#45;/g, '-').replace(/\\s+/g, ' '); const candidates = Array.from(ROW.querySelectorAll('[itemprop=\"telephone\"], .mlr__sub-text, .listing__phone, .phone, [class*=\"phone\" i], a[href^=\"tel:\"], [data-phone], [data-tel], [data-telephone], [data-analytics-placeholder], [data-analytics]')); for (const el of candidates) { const href = el.getAttribute('href') || ''; const attrs = Array.from(el.attributes || []).map(a => a.name + '=' + a.value).join(' '); let raw = normalize([href.startsWith('tel:') ? href.replace(/^tel:/, '') : '', el.textContent || '', el.getAttribute('data-phone') || '', el.getAttribute('data-tel') || '', el.getAttribute('data-telephone') || '', attrs].join(' ')); const m = raw.match(phoneRe); if (m) return m[0].trim(); } const id = ROW.getAttribute('data-listing-id') || ROW.getAttribute('data-id') || ''; const rowHtml = normalize(ROW.outerHTML); const rowMatch = rowHtml.match(phoneRe); if (rowMatch) return rowMatch[0].trim(); const rowText = normalize(ROW.textContent); const textMatch = rowText.match(phoneRe); if (textMatch) return textMatch[0].trim(); if (id) { const scripts = Array.from(document.scripts).map(s => s.textContent || '').join(' '); const idx = scripts.indexOf(id); if (idx >= 0) { const slice = normalize(scripts.slice(Math.max(0, idx - 3000), idx + 3000)); const scriptMatch = slice.match(phoneRe); if (scriptMatch) return scriptMatch[0].trim(); } } return ''; })()",
            "attribute": "text",
            "isJs": true
          },
          {
            "name": "website",
            "selector": "(() => { const links = Array.from(ROW.querySelectorAll('a[href]')); const link = links.find(a => /\\/gourl\\//i.test(a.href) || /site web|website/i.test(a.textContent || '') || /website/i.test(a.className || '')); return link ? link.href : ''; })()",
            "attribute": "text",
            "isJs": true
          },
          {
            "name": "url_detaille",
            "selector": "(() => { const links = Array.from(ROW.querySelectorAll('a[href]')); const link = links.find(a => /\\/bus\\//i.test(a.getAttribute('href') || '') || /\\/bus\\//i.test(a.href)); if (!link) return ''; try { const u = new URL(link.getAttribute('href'), location.origin); u.hash = ''; return u.href; } catch (e) { return (link.href || '').split('#')[0]; } })()",
            "attribute": "text",
            "isJs": true
          }
        ]
      }
    },
    {
      "block_id": "inject-javascript-2",
      "block_type": "process",
      "title": "Inject JavaScript",
      "description": "Execute custom JavaScript",
      "position_x": 3144,
      "position_y": 220,
      "config": {
        "jsCode": "(() => { const old = document.querySelector('#uscraper-no-next-page'); if (old) old.remove(); const match = location.pathname.match(/\\/search\\/si\\/(\\d+)\\//i); if (!match) { const marker = document.createElement('div'); marker.id = 'uscraper-no-next-page'; marker.style.display = 'none'; document.body.appendChild(marker); return 'not a search result page'; } const currentPage = parseInt(match[1], 10); if (currentPage >= 100) { const marker = document.createElement('div'); marker.id = 'uscraper-no-next-page'; marker.style.display = 'none'; document.body.appendChild(marker); return 'safety stop at page ' + currentPage; } const nextPath = location.pathname.replace(/\\/search\\/si\\/\\d+\\//i, '/search/si/' + (currentPage + 1) + '/'); const nextUrl = location.origin + nextPath + location.search + location.hash; window.location.href = nextUrl; return 'navigating to next search page: ' + nextUrl; })()",
        "waitForCompletion": true,
        "timeout": 10,
        "color": "bg-[#a56eff]"
      }
    },
    {
      "block_id": "sleep-2",
      "block_type": "process",
      "title": "Sleep",
      "description": "Wait for specified time",
      "position_x": 3480,
      "position_y": 220,
      "config": {
        "duration": 3,
        "color": "bg-[#08bdba]"
      }
    },
    {
      "block_id": "wait-for-page-load-2",
      "block_type": "process",
      "title": "Wait for Page Load",
      "description": "Wait for page to finish loading",
      "position_x": 3816,
      "position_y": 220,
      "config": {
        "timeout": 30,
        "color": "bg-[#08bdba]"
      }
    },
    {
      "block_id": "wait-for-element-2",
      "block_type": "process",
      "title": "Wait for Element",
      "description": "Wait until element appears",
      "position_x": 4152,
      "position_y": 220,
      "config": {
        "selector": "body",
        "timeout": 30,
        "visible": true,
        "color": "bg-[#08bdba]"
      }
    },
    {
      "block_id": "element-exists-1",
      "block_type": "process",
      "title": "Element Exists",
      "description": "Check if element exists",
      "position_x": 4488,
      "position_y": 220,
      "config": {
        "selector": "#uscraper-no-next-page",
        "color": "bg-[#ff832b]"
      }
    },
    {
      "block_id": "end-1",
      "block_type": "output",
      "title": "End",
      "description": "Terminate execution flow",
      "position_x": 4824,
      "position_y": 520,
      "config": {
        "color": "bg-[#8d8d8d]"
      }
    },
    {
      "block_id": "element-exists-2",
      "block_type": "process",
      "title": "Element Exists",
      "description": "Check if element exists",
      "position_x": 4488,
      "position_y": 520,
      "config": {
        "selector": "div.listing[data-listing-id], div.listing",
        "color": "bg-[#ff832b]"
      }
    }
  ],
  "connections": [
    {
      "from_block_id": "set-window-size-1",
      "from_connector_id": "right",
      "to_block_id": "navigate-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "navigate-1",
      "from_connector_id": "right",
      "to_block_id": "wait-for-page-load-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "wait-for-page-load-1",
      "from_connector_id": "right",
      "to_block_id": "inject-javascript-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "inject-javascript-1",
      "from_connector_id": "right",
      "to_block_id": "sleep-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "sleep-1",
      "from_connector_id": "right",
      "to_block_id": "wait-for-element-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "wait-for-element-1",
      "from_connector_id": "right",
      "to_block_id": "inject-javascript-3",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "inject-javascript-3",
      "from_connector_id": "right",
      "to_block_id": "sleep-3",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "sleep-3",
      "from_connector_id": "right",
      "to_block_id": "structured-export-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "structured-export-1",
      "from_connector_id": "right",
      "to_block_id": "inject-javascript-2",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "inject-javascript-2",
      "from_connector_id": "right",
      "to_block_id": "sleep-2",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "sleep-2",
      "from_connector_id": "right",
      "to_block_id": "wait-for-page-load-2",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "wait-for-page-load-2",
      "from_connector_id": "right",
      "to_block_id": "wait-for-element-2",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "wait-for-element-2",
      "from_connector_id": "right",
      "to_block_id": "element-exists-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "element-exists-1",
      "from_connector_id": "true",
      "to_block_id": "end-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "element-exists-1",
      "from_connector_id": "false",
      "to_block_id": "element-exists-2",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "element-exists-2",
      "from_connector_id": "true",
      "to_block_id": "inject-javascript-3",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "element-exists-2",
      "from_connector_id": "false",
      "to_block_id": "end-1",
      "to_connector_id": "left"
    }
  ],
  "canvas_elements": [
    {
      "id": "group-entry",
      "element_type": "group",
      "title": "Entry & Setup",
      "color": "#4589ff",
      "position_x": 48,
      "position_y": 116,
      "width": 380,
      "height": 296,
      "z_index": 20,
      "data": {
        "memberBlockIds": [
          "set-window-size-1"
        ]
      }
    },
    {
      "id": "group-load",
      "element_type": "group",
      "title": "Page Load",
      "color": "#08bdba",
      "position_x": 384,
      "position_y": 116,
      "width": 4016,
      "height": 296,
      "z_index": 20,
      "data": {
        "memberBlockIds": [
          "navigate-1",
          "wait-for-page-load-1",
          "sleep-1",
          "wait-for-element-1",
          "sleep-3",
          "sleep-2",
          "wait-for-page-load-2",
          "wait-for-element-2"
        ]
      }
    },
    {
      "id": "group-interaction",
      "element_type": "group",
      "title": "Interaction",
      "color": "#a56eff",
      "position_x": 1056,
      "position_y": 116,
      "width": 2336,
      "height": 296,
      "z_index": 20,
      "data": {
        "memberBlockIds": [
          "inject-javascript-1",
          "inject-javascript-3",
          "inject-javascript-2"
        ]
      }
    },
    {
      "id": "group-extract",
      "element_type": "group",
      "title": "Data Extraction",
      "color": "#42be65",
      "position_x": 2736,
      "position_y": 116,
      "width": 380,
      "height": 296,
      "z_index": 20,
      "data": {
        "memberBlockIds": [
          "structured-export-1"
        ]
      }
    },
    {
      "id": "group-pagination",
      "element_type": "group",
      "title": "Pagination Loop",
      "color": "#ff832b",
      "position_x": 4416,
      "position_y": 116,
      "width": 380,
      "height": 596,
      "z_index": 20,
      "data": {
        "memberBlockIds": [
          "element-exists-1",
          "element-exists-2"
        ]
      }
    },
    {
      "id": "group-control",
      "element_type": "group",
      "title": "Control Flow",
      "color": "#8d8d8d",
      "position_x": 4752,
      "position_y": 416,
      "width": 380,
      "height": 296,
      "z_index": 20,
      "data": {
        "memberBlockIds": [
          "end-1"
        ]
      }
    },
    {
      "id": "note-overview",
      "element_type": "note",
      "title": "Overview",
      "content": "Scrapes PagesJaunes.ca business search results for the default query Restaurants; Montreal QC. Exports business name, location, description, category/type, telephone, website redirect URL, and detail URL. Pagination is implemented by incrementing the /search/si/{page}/ URL after each extraction and looping until no listing rows are found. Phone extraction is best-effort because PagesJaunes may hide/reveal phone numbers dynamically.",
      "color": "#f1c21b",
      "position_x": 80,
      "position_y": 20,
      "width": 480,
      "height": 160,
      "z_index": 22,
      "data": {}
    },
    {
      "id": "note-block-inject-javascript-1",
      "element_type": "note",
      "title": "Note: Inject JavaScript",
      "content": "Runs custom JavaScript in the page: `(() => { const selectors = ['button[id*=\"accept\" i]', 'button[class*=\"accept\" i]', '[class*=\"consent...` Verify in browser if results are empty.",
      "color": "#ee5396",
      "position_x": 1328,
      "position_y": 200,
      "width": 340,
      "height": 140,
      "z_index": 22,
      "data": {
        "block_id": "inject-javascript-1"
      }
    },
    {
      "id": "note-block-inject-javascript-3",
      "element_type": "note",
      "title": "Note: Inject JavaScript",
      "content": "Runs custom JavaScript in the page: `(() => { const rows = Array.from(document.querySelectorAll('div.listing[data-listing-id], div.listin...` Verify in browser if results are empty.",
      "color": "#ee5396",
      "position_x": 2336,
      "position_y": 200,
      "width": 340,
      "height": 140,
      "z_index": 22,
      "data": {
        "block_id": "inject-javascript-3"
      }
    },
    {
      "id": "note-block-structured-export-1",
      "element_type": "note",
      "title": "Note: Structured Export",
      "content": "Structured export with JS columns (nom_du_magasin, location, avis_des_magasins, type_domaine, telephone). These selectors are fragile — update if the site layout changes.",
      "color": "#ee5396",
      "position_x": 3008,
      "position_y": 200,
      "width": 340,
      "height": 136,
      "z_index": 22,
      "data": {
        "block_id": "structured-export-1"
      }
    },
    {
      "id": "note-block-inject-javascript-2",
      "element_type": "note",
      "title": "Note: Inject JavaScript",
      "content": "Runs custom JavaScript in the page: `(() => { const old = document.querySelector('#uscraper-no-next-page'); if (old) old.remove(); const ...` Verify in browser if results are empty.",
      "color": "#ee5396",
      "position_x": 3344,
      "position_y": 200,
      "width": 340,
      "height": 140,
      "z_index": 22,
      "data": {
        "block_id": "inject-javascript-2"
      }
    },
    {
      "id": "note-block-element-exists-1",
      "element_type": "note",
      "title": "Note: Element Exists",
      "content": "Condition block: checks `#uscraper-no-next-page`. True / False branches control which path runs next. Keep enough space between branches so both connector lines are visible.",
      "color": "#ee5396",
      "position_x": 4688,
      "position_y": 200,
      "width": 340,
      "height": 137,
      "z_index": 22,
      "data": {
        "block_id": "element-exists-1"
      }
    },
    {
      "id": "note-block-element-exists-2",
      "element_type": "note",
      "title": "Note: Element Exists",
      "content": "Condition block: checks `div.listing[data-listing-id], div.listing`. True / False branches control which path runs next. Keep enough space between branches so both connector lines are visible.",
      "color": "#ee5396",
      "position_x": 4688,
      "position_y": 500,
      "width": 340,
      "height": 144,
      "z_index": 22,
      "data": {
        "block_id": "element-exists-2"
      }
    }
  ]
}