Building an Amazon Price Tracker with Python and WayScript

Subscribe to my newsletter and never miss my upcoming articles

Hi Well, Today we will discuss How to built Amazon Price Tracker by scraping the price details and scheduling with WayScript

Lemme tell you the real reason to build this ;) I'm a foodie I love Nutella 🤤 but due to this pandemic, I couldn't find Nutella near me in any local stores. So I thought to order it in Amazon but the prices are damn high and prices are fluctuating too... then I started to build a tracker which notifies me whenever the price goes down the tracking price.

Let's get started..

We gonna create a python script which uses request and beautifulSoup module to scrape the data and scheduling the script to run every hour either with Serverless AWS Lambda or WayScript but AWS Lambda is not my cup of tea. So I built using WayScript.

We will discuss this process in 2 phases. Phase I : Scraping the product details Phase II : Scheduling the script to run every hour

Phase I:

Step 1: Create an excel sheet with urls and Tracking Price
Alt Text

Step 2: import necessary packages/module

import requests
import bs4
import pandas as pd

Request - The requests module allows you to send HTTP requests using Python bs4 - Beautiful Soup is a library that makes it easy to scrape information from web pandas - pandas is a fast and powerful used for data analysis. we are faking ourselves as a Firefox user to avoid restrictions.

HEADERS = ({'User-Agent':
            'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36',
            'Accept-Language': 'en-US, en;q=0.5'})

Step 3: Building Python Script Here is the tracker function which takes parameters URL and TrackingPrice and adds the details of the product when it is less or than equal to TrackingPrice


def tracker(url,TrackingPrice):
    res = requests.get(url,headers=HEADERS)
    soup = bs4.BeautifulSoup(res.content, features='lxml')

    # to prevent script from crashing when there isn't a price for the product
    try:
        title = soup.find(id="productTitle").get_text().strip()
        amount = float(soup.find(id='priceblock_ourprice').get_text().replace("₹","").replace("$","").strip())
        if amount<=TrackingPrice:
            offer.append("You got a offer on the {0} for {1}. Check out the product {2}".format(title,amount,url))


    except:
        offer.append("Couldn't get details about product")


Source Code:

import requests
import bs4
import pandas as pd


HEADERS = ({'User-Agent':
            'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36',
            'Accept-Language': 'en-US, en;q=0.5'})
offer=[]
def tracker(url,TrackingPrice):
    res = requests.get(url,headers=HEADERS)
    soup = bs4.BeautifulSoup(res.content, features='lxml')

    # to prevent script from crashing when there isn't a price for the product
    try:
        title = soup.find(id="productTitle").get_text().strip()
        amount = float(soup.find(id='priceblock_ourprice').get_text().replace("₹","").replace("$","").strip())
        if amount<=TrackingPrice:
            offer.append("You got a offer on the {0} for {1}. Check out the product {2}".format(title,amount,url))


    except:
        offer.append("Couldn't get details about product")



df=pd.read_csv("https://docs.google.com/spreadsheets/d/1AzJ93zR6--4vwl81W3v0FHyZ_bFMkFYRxOSjodJu_Qw/export?format=csv")
for i in range(0,len(df["URL"])):
    tracker(df["URL"][i],df["TrackingPrice"][i])
outputs["message"]=offer

Output:

Alt Text


we're done with our python script
Now let's move to Phase II

Phase II:
I already told you can schedule this script either by using AWS Lambda or any other cloud computing services as I'm not familar with AWS. I'm going with WayScript

And this WayScript provide wide range of packages to interact with services Ex:

  • Gmail
  • Text Message
  • Charts
  • Figma
  • Slack
  • Trello
  • Twitter

Step 1: Open WayScript
Packages used for this scheduling:

  • Time Trigger
  • Python
  • Loop
  • Text Message
Step 2: Explaining everything in blog is not possible and people get cumbersome. So I made video of "How to configure the Python Script in WayScript. Kindly Follow the video

Click here to check my configuration in WayScript

On one lucky day..

The price got reduced and this script notified me by sending a text message and I ordered it 😁
Alt Text
If you like my content, please consider supporting me


No Comments Yet