{
  "name": "Amazon Product Scraper to Google Sheets",
  "nodes": [
    {
      "parameters": {
        "url": "http://api.scrape.do",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "url",
              "value": "https://us.amazon.com/Amazon-Basics-Portable-Adjustable-Notebook/dp/B0BLRJ4R8F/?th=1"
            },
            {
              "name": "token",
              "value": "<your-SDO-token>"
            },
            {
              "name": "super",
              "value": "true"
            },
            {
              "name": "geoCode",
              "value": "us"
            },
            {
              "name": "output",
              "value": "markdown"
            },
            {
              "name": "render",
              "value": "false"
            }
          ]
        },
        "options": {
          "redirect": {
            "redirect": {}
          }
        }
      },
      "name": "Scrape Amazon Page",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [-400, 144],
      "id": "6765a92c-66f3-47e1-9761-e8cf3d13d3ba"
    },
    {
      "parameters": {
        "language": "python",
        "pythonCode": "import re\nfrom datetime import datetime\n\n# Get HTML from previous node\nhtml = str(items[0]['json'].get('data', ''))\n\n# Extract product name\nname_match = re.search(r'<span id=\"productTitle\"[^>]*>(.*?)</span>', html, re.DOTALL)\nname = re.sub(r'\\s+', ' ', name_match.group(1)).strip() if name_match else \"Name not found\"\n\n# Extract ASIN\nasin_patterns = [r'\"asin\":\"([A-Z0-9]{10})\"', r'data-asin=\"([A-Z0-9]{10})\"']\nasin = \"ASIN not found\"\nfor pattern in asin_patterns:\n    m = re.search(pattern, html)\n    if m:\n        asin = m.group(1)\n        break\n\n# Extract price\nprice_match = re.search(r'<span class=\"a-offscreen\">\\$([0-9.,]+)</span>', html)\nif price_match:\n    price = f\"${price_match.group(1)}\"\nelse:\n    whole = re.search(r'<span class=\"a-price-whole\">([0-9,]+)', html)\n    fraction = re.search(r'<span class=\"a-price-fraction\">([0-9]+)</span>', html)\n    price = f\"${whole.group(1)}.{fraction.group(1)}\" if whole and fraction else \"Price not found\"\n\n# Extract image\nimage_match = re.search(r'id=\"landingImage\"[^>]*data-a-dynamic-image=\"[^\"]*&quot;(https://[^&]+?)&quot;', html)\nif not image_match:\n    image_match = re.search(r'<img[^>]*id=\"landingImage\"[^>]*src=\"([^\"]+)\"', html)\nimage = image_match.group(1) if image_match else \"No image\"\n\n# Extract rating\nrating_match = re.search(r'(\\d+\\.?\\d*)\\s*out of', html)\nrating = rating_match.group(1) if rating_match else \"No rating\"\n\n# Return output\nreturn [{'json': {'asin': asin, 'name': name, 'price': price, 'image': image, 'rating': rating, 'scrapedAt': datetime.now().isoformat()}}]"
      },
      "name": "Extract with Python (Code)",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [-96, 144],
      "id": "a218c021-c88c-4b00-a611-d9abfcbc64ec",
      "disabled": true
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "https://docs.google.com/spreadsheets/d/<your-spreadsheet-id>/edit?gid=0#gid=0",
          "mode": "url"
        },
        "sheetName": {
          "__rl": true,
          "value": "Sheet1",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "ASIN": "={{ $json.ASIN }}",
            "Product Name": "={{ $json.Product_Name }}",
            "Product Price": "={{ $json.Product_Price }}",
            "Product Image": "={{ $json.Brand }}",
            "Product Rating": "={{ $json.Review_Rating }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "ASIN",
              "displayName": "ASIN",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Product Name",
              "displayName": "Product Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Product Image",
              "displayName": "Product Image",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Product Price",
              "displayName": "Product Price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Product Rating",
              "displayName": "Product Rating",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "name": "Write to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [288, 144],
      "id": "679b1d16-90d2-49a0-b836-f2260954924e"
    },
    {
      "parameters": {},
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [-576, 144],
      "id": "67cb0736-1b94-4354-b32a-1af3143fc81b"
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "claude-sonnet-4-5-20250929",
          "mode": "list",
          "cachedResultName": "claude-sonnet-4-5-20250929"
        },
        "messages": {
          "values": [
            {
              "content": "={{ $json.data }} Analyze the markdown data in this document and extract ASIN, Product Name, Product Price, Review Rating, and Review Count as a structured JSON table."
            }
          ]
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.anthropic",
      "typeVersion": 1,
      "position": [-192, 336],
      "id": "67a18f37-ef95-4279-a547-e71228a00f52",
      "name": "Message a model"
    },
    {
      "parameters": {
        "instructions": "Extract JSON items in the text content input as separate data points to in the output.",
        "codeGeneratedForPrompt": "Extract JSON items in the text content input as separate data points to in the output.",
        "jsCode": "const items = $input.all();\nconst extractedItems = items.map((item) => {\n  const textContent = item?.json?.content[0]?.text;\n  const jsonDataStart = textContent.indexOf(\"{\");\n  const jsonDataEnd = textContent.lastIndexOf(\"}\") + 1;\n  const jsonData = textContent.slice(jsonDataStart, jsonDataEnd);\n  const jsonObject = JSON.parse(jsonData);\n  return { json: jsonObject };\n});\nreturn extractedItems;\n"
      },
      "type": "n8n-nodes-base.aiTransform",
      "typeVersion": 1,
      "position": [112, 336],
      "id": "2fb2a2ee-aff8-4ce3-a8ec-76d4434cff43",
      "name": "AI Transform"
    }
  ],
  "pinData": {},
  "connections": {
    "Scrape Amazon Page": {
      "main": [
        [
          {
            "node": "Extract with Python (Code)",
            "type": "main",
            "index": 0
          },
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract with Python (Code)": {
      "main": [
        [
          {
            "node": "Write to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Scrape Amazon Page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message a model": {
      "main": [
        [
          {
            "node": "AI Transform",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Transform": {
      "main": [
        [
          {
            "node": "Write to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "14b7f0b9-0725-466b-8866-27dd06306ab8",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "tags": []
}
