{
  "version": "1.0.0",
  "exported_at": "2026-06-02T00:00:00.000Z",
  "project": {
    "name": "Yellow Pages Thailand Scraper",
    "description": "Scrapes YellowPages Thailand search results from yellowpages.co.th by keyword. The template uses sample keyword search URLs, tags listing containers with an injected DOM-normalization script, extracts company name, address, category, telephone, fax, opening hours, coordinates, business information, products/services, and profile URL, then follows Next pagination until no more result pages remain before continuing to the next keyword URL. Edit navigate.urls to add or replace keywords. Best-effort template because the target site may vary listing-card markup and some rich fields may only appear on detail pages.",
    "color": "bg-[#ff832b]",
    "template_id": "ai-generated"
  },
  "blocks": [
    {
      "block_id": "navigate-1",
      "block_type": "process",
      "title": "Navigate",
      "description": "Go to a URL",
      "position_x": 120,
      "position_y": 220,
      "config": {
        "urls": [
          "https://www.yellowpages.co.th/ypsearch?q=%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%99%E0%B8%AD%E0%B8%B2%E0%B8%AB%E0%B8%B2%E0%B8%A3",
          "https://www.yellowpages.co.th/ypsearch?q=%E0%B8%9A%E0%B8%A3%E0%B8%B4%E0%B8%A9%E0%B8%B1%E0%B8%97%E0%B8%97%E0%B8%B5%E0%B9%88%E0%B8%9B%E0%B8%A3%E0%B8%B6%E0%B8%81%E0%B8%A9%E0%B8%B2%E0%B8%97%E0%B8%B2%E0%B8%87%E0%B9%80%E0%B8%97%E0%B8%84%E0%B9%82%E0%B8%99%E0%B9%82%E0%B8%A5%E0%B8%A2%E0%B8%B5",
          "https://www.yellowpages.co.th/ypsearch?q=%E0%B9%82%E0%B8%A3%E0%B8%87%E0%B9%81%E0%B8%A3%E0%B8%A1",
          "https://www.yellowpages.co.th/ypsearch?q=%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%83%E0%B8%AB%E0%B9%89%E0%B8%84%E0%B8%B3%E0%B8%9B%E0%B8%A3%E0%B8%B6%E0%B8%81%E0%B8%A9%E0%B8%B2%E0%B8%97%E0%B8%B2%E0%B8%87%E0%B8%98%E0%B8%B8%E0%B8%A3%E0%B8%81%E0%B8%B4%E0%B8%88"
        ],
        "color": "bg-[#4589ff]"
      }
    },
    {
      "block_id": "wait-for-page-load-1",
      "block_type": "process",
      "title": "Wait for Page Load",
      "description": "Wait for page to finish loading",
      "position_x": 480,
      "position_y": 220,
      "config": {
        "timeout": 30
      }
    },
    {
      "block_id": "sleep-1",
      "block_type": "process",
      "title": "Sleep",
      "description": "Wait for specified time",
      "position_x": 840,
      "position_y": 220,
      "config": {
        "duration": 2
      }
    },
    {
      "block_id": "inject-javascript-1",
      "block_type": "process",
      "title": "Inject JavaScript",
      "description": "Run custom JavaScript on the page",
      "position_x": 1200,
      "position_y": 220,
      "config": {
        "jsCode": "(() => {\n  document.querySelectorAll('[data-uscraper-yp-row]').forEach(el => el.removeAttribute('data-uscraper-yp-row'));\n\n  const marked = new Set();\n  const bad = new Set([document.documentElement, document.body]);\n  const phoneRe = /(?:0\\d[\\d\\-\\s]{7,}|08\\d[\\d\\-\\s]{7,}|09\\d[\\d\\-\\s]{7,})/;\n  const addressRe = /(จังหวัด|อำเภอ|ตำบล|แขวง|เขต|กรุงเทพ|กรุงเทพมหานคร|ถนน|Thailand|Bangkok)/i;\n\n  function cleanText(el) {\n    return (el && el.textContent ? el.textContent : '').replace(/\\s+/g, ' ').trim();\n  }\n\n  function likelyContainer(el) {\n    if (!el || bad.has(el)) return false;\n    const txt = cleanText(el);\n    if (txt.length < 40 || txt.length > 5000) return false;\n    const hasLink = !!el.querySelector('a[href*=\"/profile\"], h1 a, h2 a, h3 a, h4 a, .title a, .company-name a');\n    const hasBusinessSignal = phoneRe.test(txt) || addressRe.test(txt) || !!el.querySelector('[class*=\"address\"], [class*=\"phone\"], [class*=\"tel\"], [class*=\"category\"], [class*=\"business\"], [class*=\"company\"]');\n    return hasLink && hasBusinessSignal;\n  }\n\n  function chooseContainer(anchor) {\n    let best = null;\n    let cur = anchor;\n    for (let i = 0; i < 9 && cur && !bad.has(cur); i++, cur = cur.parentElement) {\n      if (likelyContainer(cur)) {\n        best = cur;\n        if (cur.matches('article, li, .card, .media, .views-row, .result, .result-item, .business-listing, .yp-list-item, .company-item, [class*=\"result\"], [class*=\"listing\"], [class*=\"business\"], [class*=\"company\"]')) break;\n      }\n    }\n    return best;\n  }\n\n  const anchors = Array.from(document.querySelectorAll('a[href*=\"/profile\"], a[href*=\"/profiles\"], h1 a, h2 a, h3 a, h4 a, .title a, .company-name a'));\n  anchors.forEach(a => {\n    const box = chooseContainer(a);\n    if (box) marked.add(box);\n  });\n\n  const candidateBoxes = Array.from(document.querySelectorAll('article, li, .card, .media, .views-row, .result, .result-item, .business-listing, .yp-list-item, .company-item, [class*=\"result\"], [class*=\"listing\"], [class*=\"business\"], [class*=\"company\"]'));\n  candidateBoxes.forEach(el => {\n    if (likelyContainer(el)) marked.add(el);\n  });\n\n  Array.from(marked).forEach((el, idx) => {\n    el.setAttribute('data-uscraper-yp-row', '1');\n    el.setAttribute('data-uscraper-yp-index', String(idx + 1));\n  });\n\n  return String(marked.size);\n})()",
        "waitForCompletion": true,
        "timeout": 10
      }
    },
    {
      "block_id": "wait-for-element-1",
      "block_type": "process",
      "title": "Wait for Element",
      "description": "Wait until element appears",
      "position_x": 1560,
      "position_y": 220,
      "config": {
        "selector": "[data-uscraper-yp-row=\"1\"]",
        "timeout": 30,
        "visible": true
      }
    },
    {
      "block_id": "structured-export-1",
      "block_type": "process",
      "title": "Structured Export",
      "description": "Export data with custom columns",
      "position_x": 1920,
      "position_y": 220,
      "config": {
        "rowSelector": "[data-uscraper-yp-row=\"1\"]",
        "fileName": "yellow-pages-thailand-scraper.csv",
        "saveLocation": "C:\\Users\\theskd\\Documents\\UScraper\\templates",
        "includeHeaders": true,
        "fileMode": "append",
        "columns": [
          {
            "name": "keyword",
            "selector": "(()=>{const u=new URL(location.href);return decodeURIComponent(u.searchParams.get('q')||u.searchParams.get('keyword')||u.searchParams.get('search')||'');})()",
            "attribute": "text",
            "isJs": true
          },
          {
            "name": "business_name",
            "selector": "(()=>{const el=ROW.querySelector('h1 a,h2 a,h3 a,h4 a,.title a,.company-name a,a[href*=\"/profile\"]');return el?el.textContent.trim().replace(/\\s+/g,' '):'';})()",
            "attribute": "text",
            "isJs": true
          },
          {
            "name": "address",
            "selector": "(()=>{const direct=ROW.querySelector('[class*=\"address\"],.address,.views-field-field-address,[itemprop=\"address\"]');if(direct)return direct.textContent.trim().replace(/\\s+/g,' ');const txt=ROW.textContent.replace(/\\s+/g,' ').trim();const m=txt.match(/((?:ตำบล|แขวง|อำเภอ|เขต|จังหวัด|กรุงเทพมหานคร|กรุงเทพ|ถนน).{10,160}(?:\\d{5})?)/);return m?m[1].trim():'';})()",
            "attribute": "text",
            "isJs": true
          },
          {
            "name": "category",
            "selector": "(()=>{const els=Array.from(ROW.querySelectorAll('a[href*=\"/heading\"],a[href*=\"/category\"],a[href*=\"/categories\"],[class*=\"category\"] a,.category a,.views-field-field-category a'));return [...new Set(els.map(e=>e.textContent.trim().replace(/\\s+/g,' ')).filter(Boolean))].join(' | ');})()",
            "attribute": "text",
            "isJs": true
          },
          {
            "name": "telephone",
            "selector": "(()=>{const vals=Array.from(ROW.querySelectorAll('a[href^=\"tel:\"],[class*=\"tel\"],[class*=\"phone\"],.phone')).map(e=>e.textContent.trim().replace(/\\s+/g,' ')).filter(Boolean);if(vals.length)return [...new Set(vals)].join(' | ');const txt=ROW.textContent.replace(/\\s+/g,' ');const matches=txt.match(/(?:0\\d[\\d\\-\\s]{7,}|08\\d[\\d\\-\\s]{7,}|09\\d[\\d\\-\\s]{7,})/g)||[];return [...new Set(matches.map(s=>s.trim()))].join(' | ');})()",
            "attribute": "text",
            "isJs": true
          },
          {
            "name": "fax",
            "selector": "(()=>{const el=ROW.querySelector('[class*=\"fax\"],.fax');if(el)return el.textContent.trim().replace(/\\s+/g,' ');const t=ROW.textContent.replace(/\\s+/g,' ');const m=t.match(/(?:แฟกซ์|Fax|FAX)\\s*[:：]?\\s*([0-9\\-\\s,]+)/);return m?m[1].trim():'';})()",
            "attribute": "text",
            "isJs": true
          },
          {
            "name": "opening_hours",
            "selector": "(()=>{const el=ROW.querySelector('[class*=\"hour\"],[class*=\"open\"],[class*=\"time\"],.opening-hours,[itemprop=\"openingHours\"]');if(el)return el.textContent.trim().replace(/\\s+/g,' ');const t=ROW.textContent.replace(/\\s+/g,' ');const m=t.match(/((?:เปิด|เวลา|จันทร์|เสาร์|อาทิตย์|ทุกวัน|24 ชั่วโมง).{0,120})/);return m?m[1].trim():'';})()",
            "attribute": "text",
            "isJs": true
          },
          {
            "name": "coordinates",
            "selector": "(()=>{const text=ROW.textContent;const m=text.match(/-?\\d{1,2}\\.\\d+\\s*,\\s*-?\\d{1,3}\\.\\d+/);if(m)return m[0];const href=(ROW.querySelector('a[href*=\"maps\"],a[href*=\"google.com/maps\"],a[href*=\"map\"]')||{}).href||'';const hm=href.match(/-?\\d{1,2}\\.\\d+%2C-?\\d{1,3}\\.\\d+|-?\\d{1,2}\\.\\d+,\\s*-?\\d{1,3}\\.\\d+/);return hm?decodeURIComponent(hm[0]):'';})()",
            "attribute": "text",
            "isJs": true
          },
          {
            "name": "business_info",
            "selector": "(()=>{const el=ROW.querySelector('[class*=\"description\"],[class*=\"summary\"],[class*=\"detail\"],.field--name-body,.views-field-body,[itemprop=\"description\"]');if(el)return el.textContent.trim().replace(/\\s+/g,' ');const clone=ROW.cloneNode(true);clone.querySelectorAll('script,style,nav,button,a[href^=\"tel:\"]').forEach(e=>e.remove());return clone.textContent.trim().replace(/\\s+/g,' ').slice(0,600);})()",
            "attribute": "text",
            "isJs": true
          },
          {
            "name": "products_services",
            "selector": "(()=>{const el=ROW.querySelector('[class*=\"product\"],[class*=\"service\"],[class*=\"สินค้า\"],[class*=\"บริการ\"]');return el?el.textContent.trim().replace(/\\s+/g,' '):'';})()",
            "attribute": "text",
            "isJs": true
          },
          {
            "name": "profile_url",
            "selector": "(()=>{const el=ROW.querySelector('a[href*=\"/profile\"],a[href*=\"/profiles\"],h1 a,h2 a,h3 a,h4 a,.title a,.company-name a');return el?el.href:'';})()",
            "attribute": "text",
            "isJs": true
          },
          {
            "name": "page_url",
            "selector": "location.href",
            "attribute": "text",
            "isJs": true
          }
        ]
      }
    },
    {
      "block_id": "element-exists-1",
      "block_type": "process",
      "title": "Element Exists",
      "description": "Check if element exists",
      "position_x": 2280,
      "position_y": 220,
      "config": {
        "selector": "a[rel=\"next\"], .pager__item--next:not(.is-disabled) a, li.pager__item--next:not(.disabled) a, ul.pagination li.next:not(.disabled) a, .pagination a[aria-label*=\"Next\"], .pagination a[title*=\"Next\"], .pagination a[aria-label*=\"ถัดไป\"]"
      }
    },
    {
      "block_id": "click-1",
      "block_type": "process",
      "title": "Click",
      "description": "Click on element",
      "position_x": 2640,
      "position_y": 540,
      "config": {
        "selector": "a[rel=\"next\"], .pager__item--next:not(.is-disabled) a, li.pager__item--next:not(.disabled) a, ul.pagination li.next:not(.disabled) a, .pagination a[aria-label*=\"Next\"], .pagination a[title*=\"Next\"], .pagination a[aria-label*=\"ถัดไป\"]",
        "timeout": 10
      }
    },
    {
      "block_id": "wait-for-page-load-2",
      "block_type": "process",
      "title": "Wait for Page Load",
      "description": "Wait for page to finish loading",
      "position_x": 3000,
      "position_y": 540,
      "config": {
        "timeout": 30
      }
    },
    {
      "block_id": "sleep-2",
      "block_type": "process",
      "title": "Sleep",
      "description": "Wait for specified time",
      "position_x": 3360,
      "position_y": 540,
      "config": {
        "duration": 2
      }
    },
    {
      "block_id": "loop-continue-1",
      "block_type": "process",
      "title": "Loop Continue",
      "description": "Continue multi-input loop",
      "position_x": 2280,
      "position_y": 860,
      "config": {}
    }
  ],
  "connections": [
    {
      "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": "sleep-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "sleep-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": "wait-for-element-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "wait-for-element-1",
      "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": "element-exists-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "element-exists-1",
      "from_connector_id": "true",
      "to_block_id": "click-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "element-exists-1",
      "from_connector_id": "false",
      "to_block_id": "loop-continue-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "click-1",
      "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": "sleep-2",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "sleep-2",
      "from_connector_id": "right",
      "to_block_id": "inject-javascript-1",
      "to_connector_id": "left"
    }
  ],
  "canvas_elements": [
    {
      "id": "group-load",
      "element_type": "group",
      "title": "Page Load",
      "color": "#08bdba",
      "position_x": 48,
      "position_y": 116,
      "width": 3560,
      "height": 616,
      "z_index": 20,
      "data": {
        "memberBlockIds": [
          "navigate-1",
          "wait-for-page-load-1",
          "sleep-1",
          "wait-for-element-1",
          "wait-for-page-load-2",
          "sleep-2"
        ]
      }
    },
    {
      "id": "group-interaction",
      "element_type": "group",
      "title": "Interaction",
      "color": "#a56eff",
      "position_x": 1128,
      "position_y": 116,
      "width": 380,
      "height": 296,
      "z_index": 20,
      "data": {
        "memberBlockIds": [
          "inject-javascript-1"
        ]
      }
    },
    {
      "id": "group-extract",
      "element_type": "group",
      "title": "Data Extraction",
      "color": "#42be65",
      "position_x": 1848,
      "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": 2208,
      "position_y": 116,
      "width": 680,
      "height": 936,
      "z_index": 20,
      "data": {
        "memberBlockIds": [
          "element-exists-1",
          "click-1",
          "loop-continue-1"
        ]
      }
    },
    {
      "id": "note-overview",
      "element_type": "note",
      "title": "Overview",
      "content": "Scrapes YellowPages Thailand search results from yellowpages.co.th by keyword. The template uses sample keyword search URLs, tags listing containers with an injected DOM-normalization script, extracts company name, address, category, telephone, fax, opening hours, coordinates, business information, products/services, and profile URL, then follows Next pagination until no more result pages remain before continuing to the next keyword URL. Edit navigate.urls to add or replace keywords. Best-effort template because the target site may vary listing-card markup and some rich fields may only appear on detail pages.",
      "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: `(() => {\n  document.querySelectorAll('[data-uscraper-yp-row]').forEach(el => el.removeAttribute('dat...` Verify in browser if results are empty.",
      "color": "#ee5396",
      "position_x": 1400,
      "position_y": 200,
      "width": 340,
      "height": 140,
      "z_index": 22,
      "data": {
        "block_id": "inject-javascript-1"
      }
    },
    {
      "id": "note-block-structured-export-1",
      "element_type": "note",
      "title": "Note: Structured Export",
      "content": "Structured export with JS columns (keyword, business_name, address, category, telephone). These selectors are fragile — update if the site layout changes.",
      "color": "#ee5396",
      "position_x": 2120,
      "position_y": 200,
      "width": 340,
      "height": 131,
      "z_index": 22,
      "data": {
        "block_id": "structured-export-1"
      }
    },
    {
      "id": "note-block-element-exists-1",
      "element_type": "note",
      "title": "Note: Element Exists",
      "content": "Condition block: checks `a[rel=\"next\"], .pager__item--next:not(.is-disabled) a, li.pager__item--next:not(.disabled) a, ul.pagination li.next:not(`. True / False branches control which path runs next. Keep enough space between branches so both connector lines are visible.",
      "color": "#ee5396",
      "position_x": 2480,
      "position_y": 200,
      "width": 340,
      "height": 170,
      "z_index": 22,
      "data": {
        "block_id": "element-exists-1"
      }
    },
    {
      "id": "note-block-click-1",
      "element_type": "note",
      "title": "Note: Click",
      "content": "Pagination click — add waits after this block; the page reloads asynchronously.",
      "color": "#ee5396",
      "position_x": 2840,
      "position_y": 520,
      "width": 316,
      "height": 106,
      "z_index": 22,
      "data": {
        "block_id": "click-1"
      }
    },
    {
      "id": "note-block-loop-continue-1",
      "element_type": "note",
      "title": "Note: Loop Continue",
      "content": "Loop Continue advances a multi-URL or multi-text loop. Place at the end of the loop body with a clear back-edge to the loop start.",
      "color": "#ee5396",
      "position_x": 2480,
      "position_y": 840,
      "width": 340,
      "height": 123,
      "z_index": 22,
      "data": {
        "block_id": "loop-continue-1"
      }
    }
  ]
}