I Made a Bot Do My Amazon Shopping. Here's How
0x41434f
I've always been fascinated by automation, and recently I wondered: could I actually get a software bot to buy my regular household stuff from Amazon for me? It sounds futuristic, but I wanted to give it a shot!
I decided to use Amazon Nova Act, a new tool designed to control a web browser using AI and simple text commands. My plan was to write a Python script to navigate Amazon, search for items, add them to the cart, go through checkout, and maybe even place the final order.
Well, after some trial and error (which you can read about in my post or see in the video below!), I got it working. The script successfully navigated Amazon and placed a real order for paper towels, dish soap, and more! This post explains how I set it up, the script I used, some things I learned, and very important warnings if you're thinking of trying this.
Here's a quick look at the bot in action:
Getting Started with Nova Act
Before you can automate anything, you need Nova Act set up. Here's what the official documentation says you need:
Pre-requisites:
- Operating System: MacOS or Ubuntu.
- Python 3.10 or above. (I recommend using a Python virtual environment like
.venv
to keep things organized).
Installation:
- Once you have Python ready, open your terminal and run:
python3 -m venv .venv source .venv/bin/activate pip install nova-act
Authentication (Getting Your Secret Key):
- Nova Act needs a special password, an API key, to connect to Amazon's service.
- Navigate to
https://nova.amazon.com/act
in your browser. You'll likely need to sign in with your regular Amazon account. - Generate your API key there. It will be a long string of characters.
- Treat this key like a password! Keep it secret and safe.
- You need to make this key available to your script. A common way on Mac/Linux is to set an environment variable in your terminal for the current session:
(Replace the part in quotes with your actual key).export NOVA_ACT_API_KEY="your_very_long_api_key_here"
How I Handled the Amazon Login (Without Passwords in the Script!)
Putting my Amazon password directly in a script felt like a bad idea for security. Nova Act also recommends against this because it logs information (like screenshots) while running.
So, I used the recommended method: saving a browser session where I was already logged in. It works like this:
- Run a Setup Script: Nova Act provides a helper script. I first made sure Google Chrome was completely closed. Then, I ran this in my terminal to create a dedicated profile folder (I chose
~/NovaProfiles/Amazon
):python -m nova_act.samples.setup_chrome_user_data_dir --user_data_dir ~/NovaProfiles/Amazon
- Manual Login: This opened a new Chrome window, and my terminal waited. In that new window, I went to
amazon.com
and logged in fully (username, password, any 2-factor codes). - Save Session: Once logged in, I just went back to the terminal and pressed
Enter
. This saved my active login "cookie" into the~/NovaProfiles/Amazon
folder. - Use in Main Script: Now, my main shopping script just tells Nova Act to use that folder, and it starts already logged in! (Note: If my Amazon login expires, I'd need to re-run this setup step).
Building and Running the Shopping Bot
With setup done, I wrote the script to perform the shopping tasks. The core idea is telling Nova Act what to do in plain English for each step.
Some Observations:
- It's Not Faster (Yet!): Honestly, watching the bot work felt a bit slower than doing it myself. It pauses to "think" and process what it sees on the screen between actions. But, the potential is there for it to run completely unattended!
- Adaptable Prompts: The cool thing is how you tell the bot what to do. The text instructions (like
"Search for 'paper towels'..."
) are easy to change. You could adapt this script to search for different items or even interact with other websites by changing these "prompts". - "Subscribe & Save" Confusion: I noticed on one run, the bot got confused when an item had a "Subscribe & Save" option selected by default. It tried clicking that instead of just adding the item once. A better prompt (which I've included in the script below) is to explicitly tell it:
"If visible, select the 'One-time purchase' option, then find and click the 'Add to Cart' button"
. This makes it more reliable.
Okay, HUGE WARNING TIME! (Seriously!)
While it was cool to see it work, automating online purchases is risky. The successful run I recorded for the video spent real money using my account.
- Real Money Spent: The bot uses your saved payment methods. There's no "undo" button if it buys something!
- Mistakes Happen: Scripts can have bugs. It might click the wrong item, order the wrong quantity, or fail midway through checkout.
- Security & Privacy: Checkout pages show your address and payment details. Nova Act logs interactions and can record video/screenshots. Be very aware that this sensitive info might be captured locally or in the data Nova Act collects.
- Amazon's Rules: Amazon likely prohibits automated purchasing in their Terms of Service. Using bots like this could get your account flagged or suspended.
- Getting Blocked: Amazon has anti-bot measures (like CAPTCHAs) that can stop the script at any time, especially during checkout.
How to Be Safer:
In the script code below, I've commented out the final command that actually places the order. For simply demonstrating or testing, I strongly recommend you leave it commented out. The script will stop safely right before confirming the purchase. I only uncommented it for my final test run shown in the video after accepting the risks.
The Full Python Script (with Comments!)
Here's the complete script, including the "One-time purchase" improvement and comments explaining each part.
# === Amazon Shopping Bot using Nova Act ===
# Imports needed for file paths, pausing, and the automation tool
import os
import time
from nova_act import NovaAct, ActError, BOOL_SCHEMA # Nova Act's main parts
from playwright.sync_api import Error as PlaywrightError, TimeoutError as PlaywrightTimeoutError # Potential browser errors
import logging # Useful for more detailed logs if needed
import traceback # For printing full errors if something unexpected happens
# --- Configuration ---
# --- What items do you want the bot to buy? ---
ITEMS_TO_BUY = [
"paper towels",
"dish soap",
"laundry detergent",
"trash bags"
# You can easily change these items!
]
# --- Where did you save your Amazon login session? ---
# Make sure this path matches where you ran the setup script
USER_DATA_DIR = os.path.expanduser("~/NovaProfiles/Amazon") # Adjust if needed
# --- Where should logs and videos be saved? ---
LOGS_DIR = "./nova_amazon_purchase_logs"
# --- Script Setup ---
# Create the logs folder if it doesn't already exist
os.makedirs(LOGS_DIR, exist_ok=True)
# Double-check if the login profile folder actually exists before starting
if not os.path.isdir(USER_DATA_DIR):
print(f"ERROR: Couldn't find the Amazon profile folder at '{USER_DATA_DIR}'")
print(f"Please run the setup script first:")
print(f"python -m nova_act.samples.setup_chrome_user_data_dir --user_data_dir '{USER_DATA_DIR}'")
exit(1) # Stop if profile isn't found
else:
print(f"Using Amazon User Data Directory: {USER_DATA_DIR}")
# --- Main Automation Logic ---
try:
# Let's start the browser automation!
print(f"Starting NovaAct session. Logs and video will be saved to: {LOGS_DIR}")
# Initialize Nova Act: tell it where to start, which profile to use,
# where to save logs/video, show the browser window, and record video.
with NovaAct(
starting_page="[https://www.amazon.com/](https://www.amazon.com/)",
user_data_dir=USER_DATA_DIR, # Use the pre-logged-in profile
logs_directory=LOGS_DIR,
record_video=True, # Record the browser actions
headless=False # Show the browser window (needed for video)
) as nova:
# --- Step 1: Check if we're logged in ---
print("Step 1: Verifying Amazon login...")
# Ask Nova Act a yes/no question about the page
login_check = nova.act(
"Is my name visible near the top right, indicating I'm logged in?",
schema=BOOL_SCHEMA, # Expecting True/False
max_steps=5 # Limit actions for this check
)
# Stop if login check fails
if not (login_check.matches_schema and login_check.parsed_response):
print("ERROR: Could not verify Amazon login. Is the profile in USER_DATA_DIR logged in?")
exit(1)
print("Login verified.")
time.sleep(2) # Pause briefly
# --- Steps A-C: Loop through items ---
for item in ITEMS_TO_BUY:
print("-" * 20)
print(f"Processing item: {item}")
# --- Step A: Search ---
print(f" Step A: Searching for '{item}'...")
# Tell Nova Act to use the main search bar.
nova.act(f"Search for '{item}' using the main search bar")
time.sleep(3) # Pause for search results to load
# --- Step B: Select ---
print(f" Step B: Selecting first result for '{item}'...")
# Simple approach: click the first link. Might click ads!
# For a real bot, you'd need more checks or specific product titles.
nova.act("Click the first product link in the search results")
time.sleep(5) # Pause for product page to load
# --- Step C: Add to Cart (Improved Prompt) ---
print(f" Step C: Adding '{item}' to Cart...")
# Handle "Subscribe & Save" by telling it to pick "One-time purchase" first.
nova.act("If visible, select the 'One-time purchase' option, then find and click the 'Add to Cart' button")
time.sleep(3) # Pause for confirmation/redirect
# Optional: Check if cart was updated. This check can sometimes fail.
cart_check = nova.act(
"Did an item just get added to the cart, indicated by a confirmation message or cart count increase?",
schema=BOOL_SCHEMA,
max_steps=5
)
if cart_check.matches_schema and cart_check.parsed_response:
print(f" Successfully added '{item}' to cart (or confirmed presence).")
else:
print(f" Warning: Could not confirm '{item}' was added to cart. Going back home.")
nova.act("Go back to the Amazon homepage")
time.sleep(2)
print("-" * 20)
print("Finished adding items. Proceeding to checkout...")
# --- Step D: Go to Cart ---
print("Step D: Going to Shopping Cart...")
nova.act("Navigate to the Shopping Cart page")
time.sleep(3)
# --- Step E: Proceed to Checkout ---
print("Step E: Proceeding to Checkout...")
nova.act("Click the 'Proceed to Checkout' button")
time.sleep(5) # Wait for address page
# --- Step F: Confirm Address ---
# Assumes your default address is correct and selected.
print("Step F: Confirming Shipping Address (Attempting)...")
# Click the button only if needed, otherwise continue.
nova.act("If a 'Deliver to this address' button is visible for the default address, click it. Otherwise, assume the address is selected and continue.")
time.sleep(5) # Wait for payment page
# --- Step G: Confirm Payment ---
# Assumes your default payment method is correct and selected.
print("Step G: Confirming Payment Method (Attempting)...")
# Click button only if needed.
nova.act("If a 'Continue' button or 'Use this payment method' button is visible, click it. Otherwise, assume the payment method is selected.")
time.sleep(5) # Wait for final review page
# --- Step H: Verify Final Review Page ---
print("Step H: Reaching Final Review Page (Attempting)...")
final__check = nova.act(
"Am I on the final page before placing the order, often showing 'Place your order' or 'Review your order'?",
schema=BOOL_SCHEMA,
max_steps=10
)
# Only proceed if we're on the final page
if final_check.matches_schema and final_check.parsed_response:
print("On final review page.")
# --- Step I: Place Order (DANGER ZONE!) ---
print("!!! WARNING: About to place a REAL order on Amazon !!!")
# This line was uncommented for the successful test run shown in the video,
# but is commented out here for safety in this public script.
# --- >>>>> Leave this commented out unless you fully accept ALL risks! <<< ---
# print("Step I: Clicking 'Place your order'...")
# nova.act("Click the 'Place your order' button")
# --- >>>>> End of uncommented section for test run <<<<< ---
# Keep this part active for safe demonstration:
print("Step I: 'Place your order' click is COMMENTED OUT here for safety.")
print("I uncommented this line only for my final test run shown in the video.")
# Pause the script so it stops before placing the order.
input("Stopping before final order placement. Press Enter to finish script...")
else:
# If we didn't reach the final page, stop.
print("ERROR: Could not confirm reaching the final review page. Halting.")
input("Could not reach final review page. Press Enter to finish script...")
# --- Step J: Check Confirmation (Optional) ---
# This would only run if Step I was uncommented AND successful.
print("Step J: Checking for Order Confirmation...")
# ... (confirmation check code would go here) ...
# --- Error Handling ---
# These blocks catch different types of errors and print helpful messages.
except ActError as e:
print(f"\nAn error occurred during a Nova Act action: {e}")
print("Check logs and video in:", LOGS_DIR)
except PlaywrightError as pe:
print(f"\nA Playwright error occurred: {pe}")
print("Check logs and video in:", LOGS_DIR)
except KeyboardInterrupt:
print("\nScript interrupted by user.")
except Exception as e:
print(f"\nAn unexpected error occurred: {e}")
traceback.print_exc()
# --- Script Finish ---
finally:
# This message always prints at the very end.
print("\nScript execution complete. Check logs for details and your Amazon account for order status.")
Running the Script
- Save: Save the code above as a Python file (e.g.,
my_amazon_bot.py
). - Configure: Double-check the
ITEMS_TO_BUY
list and theUSER_DATA_DIR
path. - Run Setup: Make sure you've run the
setup_chrome_user_data_dir
command for your Amazon profile recently, and Quit Chrome completely before running this script. - Execute: Open your terminal,
cd
to where you saved the file, and run:python my_amazon_bot.py
- Watch: The browser will open, and the script will perform the actions. It should pause before placing the final order.
Conclusion & Video
It was definitely an interesting project getting this bot working! It shows the power of tools like Nova Act for automating web tasks, even complex ones like shopping. While it might feel a bit slow compared to a human, the potential for running tasks automatically is huge. Remember you can adapt the prompts in the script for different items or even different websites.
Check out the video of my successful run here: https://youtu.be/7bA0dAIUfzg?
Just please, please be careful if you decide to experiment with automating real purchases. Understand the risks, start simple, and always supervise your bots closely, especially when money is involved!
Let me know what you think or if you try it out!