Amazon is one of the biggest online retailers in the world, and with the holiday season fast approaching, you'll very likely be scouring the web to find good deals on products you want to pick up for yourself or others. That's why price tracking is important, as some products will go on sale quickly and then immediately go back up after a certain number have been bought. That's why I built an Amazon price tracker, so that I can keep an eye on the best deals for certain products that I'm looking to pick up.
Of course, there are a ton of price trackers already out there that you can use, such as Keepa or CamelCamelCamel. However, this program, made in Python, is easily customizable so that you can use it for any site, not just Amazon. That means you can get price alert updates from anywhere with some simple modifications, and it can then email you when the price changes and keep a log of the price and a timestamp in a CSV file.
How I built a price tracker for Amazon
Basic web scraping
Companies typically don't like web scraping, and Amazon is no exception. However, when done right, it's completely indistuingishable from a regular user browsing the web. To start with, we'll need to pick a product we want to track the price of, and then find the HTML element where that price resides. We've gone with a PlayStation 5, just as a product that people may want to keep tabs on coming up to the holidays.
In Amazon, the price of a product is denoted under the "a-price-whole" and "a-price-fraction" classes, which means you can build a HTML parser that can find those classes and pull the information from them. You can find those classes by right clicking the price and clicking "Inspect element", which will show you the code for it and what you need to look for.
From there, we parse that data and output it to a CSV, alongside a timestamp of when it was collected. Finally, if the price changes, it then sends an email with the price change and other information. While this is personal preference, I use email as I will get a notification on all of my devices. To configure email notifications, you'll need to generate an app password if you're using Gmail with 2FA enabled.
I don’t pay for Spark, Canary, or Postbox: These are the free email apps I recommend instead
Free email apps that outshine the premium ones
Web scraping is really easy
You can pull information from any site
Because your browser has to render the text on a page when you load a site, the website obviously sends the contents of the page in plaintext to your browser. From there, you can figure out how to programmatically pull information from a page and act upon it. In this case, we're just pulling the price information. You can modify the script to pull pricing information from other sites too based on the page source code, and it's fairly modular when you find what HTML elements contain the pricing.
Websites don't like web scraping, so be sure to set it to infrequent intervals. The script by default will do it every hour, but you can increase or change it depending on how frequently you need to check. Every hour is probably good enough for most people, and can keep you on top of deals for Black Friday, Christmas, and anything else you may be interested in following. Not only that, but you control how you track webpages, so you don't need to worry about using an extension or other piece of software that could be tracking some of your data, too.
If you want to use this script, you can check it out on GitHub!
