Automating Amazon Price Tracking with Python

Photo by ThisisEngineering RAEng on Unsplash

Are you a savvy shopper who is always on the lookout for the best deals on Amazon? Do you find yourself constantly checking the prices of your favorite products to see if they have gone down? If so, you might want to consider using Python to automate the process of tracking Amazon prices. In this post, we will show you how to use Python to scrape for product prices and automate the process of checking out.

Step 1: Web Scraping

The first step in automating Amazon price tracking with Python is to scrape the product pages of for the desired product. To do this, you can use a web scraping library like BeautifulSoup or Scrapy. In the following example, we will use BeautifulSoup to scrape the product page for a MacBook Pro on

import requests
from bs4 import BeautifulSoup

def get_price(url):
    headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"}
    response = requests.get(url, headers=headers)
    soup = BeautifulSoup(response.content, 'html.parser')
    price = soup.find('span', {'class': 'a-offscreen'}).get_text().strip()
    return float(price.replace(',', '').replace('$', ''))

product_url = ''
product_price = get_price(product_url)


In this example, the get_price() function takes the URL of a product page on as input, scrapes the page for the price of the product, and returns it as a floating-point number. The headers parameter in the requests.get() function is used to simulate a web browser to bypass any anti-scraping mechanisms on

Step 2: Price Comparison

Once you have scraped the price of a product from, you can compare it with the prices of the same product on different pages or from different sellers. For example, you can check the prices of the same MacBook Pro from different sellers on or compare the prices of the MacBook Pro on with those on other websites like Best Buy or Walmart.

Step 3: Automation

Now that you can scrape product prices and compare them, you can take the automation to the next level by using an automation library like Selenium to automate the process of adding the product to the cart and checking out. Here’s an example of how to use Selenium to automate the checkout process on

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from import By
from import WebDriverWait
from import expected_conditions as EC

browser = webdriver.Chrome()
search_box = browser.find_element(By.ID, 'twotabsearchtextbox')
search_box.send_keys('MacBook Pro')

product_link = browser.find_element(By.XPATH, '//a[contains(@href, "B08L5VJYWS")]')

add_to_cart_button = browser.find_element(By.ID, 'add-to-cart-button')

proceed_to_checkout_button = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, 'hlb-ptc-btn-native')))

sign_in_button = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, 'signInSubmit')))

email_input = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.ID, 'ap_email')))

continue_button = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, 'continue')))

password_input = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.ID, 'ap_password')))

sign_in_button = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, 'signInSubmit')))

shipping_address_button = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, 'address-book-entry-0')))

continue_button = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.NAME, 'proceedToCheckout')))

place_your_order_button = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.NAME, 'placeYourOrder1')))

confirmation_message = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH, '//div[@class="a-box a-alert-success"]/div')))

This code automates the process of searching for a MacBook Pro on, adding it to the cart, signing in to your Amazon account, filling out the shipping address, and placing the order. Once the order is placed, it prints the confirmation message on the screen.

Keep in mind that Amazon may have anti-automation mechanisms in place, and using this code may be against their terms of service. Always use automation tools responsibly and with caution.