{
  "version": "1.0.0",
  "exported_at": "2026-06-02T00:00:00.000Z",
  "project": {
    "name": "Amazon Kindle Rankings Scraper Japan",
    "description": "Scrapes Amazon.co.jp Kindle Best Sellers ranking pages and exports category, category URL, rank, title, author, language, publisher, release date, price, and product URL. Pagination is handled with a known URL-list loop for page 1 and page 2 ranking URLs; structured export appends all pages into one CSV. A synchronous JavaScript enrichment step marks valid ranking rows and attempts to fetch product detail pages for language, publisher, and release date. Best-effort template: Amazon may show CAPTCHA, throttling, regional prompts, or layout changes.",
    "color": "bg-[#ff9900]",
    "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.amazon.co.jp/gp/bestsellers/digital-text/2275256051/",
          "https://www.amazon.co.jp/-/en/gp/bestsellers/digital-text/2275256051/ref=zg_bs_pg_2_digital-text?ie=UTF8&pg=2",
          "https://www.amazon.co.jp/gp/bestsellers/digital-text/2430727051/ref=zg_bs_nav_digital-text_3_2293143051",
          "https://www.amazon.co.jp/-/en/gp/bestsellers/digital-text/2430727051/ref=zg_bs_pg_2_digital-text?ie=UTF8&pg=2"
        ],
        "color": "bg-[#ff9900]",
        "tags": [
          "amazon",
          "kindle",
          "rankings",
          "pagination"
        ]
      }
    },
    {
      "block_id": "wait-for-page-load-1",
      "block_type": "process",
      "title": "Wait for Page Load",
      "description": "Wait for page to finish loading",
      "position_x": 456,
      "position_y": 220,
      "config": {
        "timeout": 45
      }
    },
    {
      "block_id": "wait-for-element-1",
      "block_type": "process",
      "title": "Wait for Element",
      "description": "Wait until element appears",
      "position_x": 792,
      "position_y": 220,
      "config": {
        "selector": "div.p13n-sc-uncoverable-faceout a[href*='/dp/']",
        "timeout": 45,
        "visible": true
      }
    },
    {
      "block_id": "inject-javascript-1",
      "block_type": "process",
      "title": "Inject JavaScript",
      "description": "Execute custom JavaScript on the page",
      "position_x": 1128,
      "position_y": 220,
      "config": {
        "jsCode": "(function(){const clean=s=>(s||'').replace(/[\\u200e\\u200f\\u202a-\\u202e]/g,'').replace(/\\s+/g,' ').trim();const abs=u=>{try{return new URL(u,location.origin).href}catch(e){return u||''}};document.querySelectorAll('.glow-toaster-button,.glow-toaster-button-dismiss').forEach(el=>{try{el.click()}catch(e){}});const h1s=Array.from(document.querySelectorAll('h1')).map(el=>clean(el.textContent));const category=(h1s.find(t=>/^Best Sellers in/i.test(t))||h1s.find(t=>/売れ筋ランキング|Best Sellers/i.test(t))||document.title).trim();const rows=Array.from(document.querySelectorAll('div.p13n-sc-uncoverable-faceout')).filter(row=>row.querySelector('a[href*=\"/dp/\"]'));function parseDetails(url){const out={language:'',publisher:'',releaseDate:''};try{const xhr=new XMLHttpRequest();xhr.open('GET',url,false);xhr.withCredentials=true;xhr.send(null);if(xhr.status<200||xhr.status>=400)return out;const doc=new DOMParser().parseFromString(xhr.responseText,'text/html');const nodes=Array.from(doc.querySelectorAll('#detailBullets_feature_div li,#productDetails_detailBullets_sections1 tr,#productDetails_techSpec_section_1 tr,.prodDetTable tr'));const labelValue=(labels)=>{for(const n of nodes){const txt=clean(n.textContent);for(const label of labels){if(txt.toLowerCase().includes(label.toLowerCase())){const th=n.querySelector('th');const td=n.querySelector('td');if(th&&td)return clean(td.textContent);let v=txt.replace(new RegExp('^.*?'+label.replace(/[.*+?^${}()|[\\]\\\\]/g,'\\\\$&')+'\\\\s*[:：]?\\\\s*','i'),'');return clean(v.replace(/^[:：\\-\\s]+/,''));}}}return '';};out.language=labelValue(['Language','言語']);let pubRaw=labelValue(['Publisher','出版社']);out.publisher=clean(pubRaw.replace(/[;(（].*$/,''));out.releaseDate=labelValue(['Publication date','Publication Date','発売日','発売年月日']);if(!out.releaseDate&&pubRaw){const m=pubRaw.match(/[\\(（]([^\\)）]*(?:\\d{4}|令和|平成)[^\\)）]*)[\\)）]/);if(m)out.releaseDate=clean(m[1]);}}catch(e){}return out;}rows.forEach((row,i)=>{const link=row.querySelector('a.a-link-normal[href*=\"/dp/\"],a[href*=\"/dp/\"]');const url=abs(link&&link.getAttribute('href'));const rank=clean(row.querySelector('.zg-bdg-text')?.textContent)||('#'+(i+1));const imgTitle=row.querySelector('img[alt]')?.getAttribute('alt')||'';const titleText=clean(row.querySelector('._cDEzb_p13n-sc-css-line-clamp-1_1Fn1y')?.textContent);const author=clean(row.querySelector('a.a-size-small.a-link-child')?.textContent);const price=clean(row.querySelector('.a-color-price')?.textContent);row.setAttribute('data-uscraper-category',category);row.setAttribute('data-uscraper-category-url',location.href);row.setAttribute('data-uscraper-ranking',rank);row.setAttribute('data-uscraper-title',clean(imgTitle||titleText));row.setAttribute('data-uscraper-author',author);row.setAttribute('data-uscraper-language','');row.setAttribute('data-uscraper-publisher','');row.setAttribute('data-uscraper-release-date','');row.setAttribute('data-uscraper-price',price);row.setAttribute('data-uscraper-product-url',url);row.setAttribute('data-uscraper-ready','1');});rows.forEach(row=>{const url=row.getAttribute('data-uscraper-product-url');if(!url)return;const d=parseDetails(url);row.setAttribute('data-uscraper-language',d.language||'');row.setAttribute('data-uscraper-publisher',d.publisher||'');row.setAttribute('data-uscraper-release-date',d.releaseDate||'');});return rows.length;})()",
        "waitForCompletion": true,
        "timeout": 600
      }
    },
    {
      "block_id": "structured-export-1",
      "block_type": "process",
      "title": "Structured Export",
      "description": "Export data with custom columns",
      "position_x": 1464,
      "position_y": 220,
      "config": {
        "rowSelector": "div.p13n-sc-uncoverable-faceout[data-uscraper-ready='1']",
        "columns": [
          {
            "name": "category",
            "selector": "",
            "attribute": "data-uscraper-category"
          },
          {
            "name": "category_url",
            "selector": "",
            "attribute": "data-uscraper-category-url"
          },
          {
            "name": "ranking",
            "selector": "",
            "attribute": "data-uscraper-ranking"
          },
          {
            "name": "title",
            "selector": "",
            "attribute": "data-uscraper-title"
          },
          {
            "name": "author",
            "selector": "",
            "attribute": "data-uscraper-author"
          },
          {
            "name": "language",
            "selector": "",
            "attribute": "data-uscraper-language"
          },
          {
            "name": "publisher",
            "selector": "",
            "attribute": "data-uscraper-publisher"
          },
          {
            "name": "release_date",
            "selector": "",
            "attribute": "data-uscraper-release-date"
          },
          {
            "name": "price",
            "selector": "",
            "attribute": "data-uscraper-price"
          },
          {
            "name": "product_url",
            "selector": "",
            "attribute": "data-uscraper-product-url"
          }
        ],
        "fileName": "amazon_jp_kindle_rankings_scraper.csv",
        "saveLocation": "C:\\Users\\theskd\\Documents\\UScraper\\templates",
        "includeHeaders": true,
        "fileMode": "append"
      }
    },
    {
      "block_id": "loop-continue-1",
      "block_type": "process",
      "title": "Loop Continue",
      "description": "Continue multi-input loop",
      "position_x": 1800,
      "position_y": 220,
      "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": "wait-for-element-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "wait-for-element-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": "structured-export-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "structured-export-1",
      "from_connector_id": "right",
      "to_block_id": "loop-continue-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": 992,
      "height": 296,
      "z_index": 20,
      "data": {
        "memberBlockIds": [
          "navigate-1",
          "wait-for-page-load-1",
          "wait-for-element-1"
        ]
      }
    },
    {
      "id": "group-interaction",
      "element_type": "group",
      "title": "Interaction",
      "color": "#a56eff",
      "position_x": 1056,
      "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": 1392,
      "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": 1728,
      "position_y": 116,
      "width": 380,
      "height": 296,
      "z_index": 20,
      "data": {
        "memberBlockIds": [
          "loop-continue-1"
        ]
      }
    },
    {
      "id": "note-overview",
      "element_type": "note",
      "title": "Overview",
      "content": "Scrapes Amazon.co.jp Kindle Best Sellers ranking pages and exports category, category URL, rank, title, author, language, publisher, release date, price, and product URL. Pagination is handled with a known URL-list loop for page 1 and page 2 ranking URLs; structured export appends all pages into one CSV. A synchronous JavaScript enrichment step marks valid ranking rows and attempts to fetch product detail pages for language, publisher, and release date. Best-effort template: Amazon may show CAPTCHA, throttling, regional prompts, or layout changes.",
      "color": "#f1c21b",
      "position_x": 80,
      "position_y": 20,
      "width": 480,
      "height": 160,
      "z_index": 22,
      "data": {}
    },
    {
      "id": "note-block-navigate-1",
      "element_type": "note",
      "title": "Note: Navigate",
      "content": "Multi-URL loop over 4 pages. Pair with loop-continue at the end of each iteration.",
      "color": "#ee5396",
      "position_x": 320,
      "position_y": 200,
      "width": 328,
      "height": 107,
      "z_index": 22,
      "data": {
        "block_id": "navigate-1"
      }
    },
    {
      "id": "note-block-inject-javascript-1",
      "element_type": "note",
      "title": "Note: Inject JavaScript",
      "content": "Runs custom JavaScript in the page: `(function(){const clean=s=>(s||'').replace(/[\\u200e\\u200f\\u202a-\\u202e]/g,'').replace(/\\s+/g,' ').tr...` 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-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": 2000,
      "position_y": 200,
      "width": 340,
      "height": 123,
      "z_index": 22,
      "data": {
        "block_id": "loop-continue-1"
      }
    }
  ]
}