Flipkart Product Price Tracker using Python


Flipkart, one of India's biggest online retailers, offers a variety of products at competitive costs, yet it may be difficult to manually monitor pricing due to Flipkart's rapid price fluctuations in response to discounts and offers. This step-by-step tutorial will teach you how to build a Python Flipkart product price tracker that will allow you to locate reasonable sales pricing and follow price changes in the background.

Syntax

To build a Flipkart product price tracker using Python, we need to install the following modules −

  • requests − to fetch the webpage of the product

  • BeautifulSoup − to parse the HTML content of the webpage and extract the product name and price

  • re − to extract the numerical value of the price from the extracted string

  • time − to add a time delay between subsequent requests to the webpage

The code can be written in any Python IDE like PyCharm or Visual Studio Code. Here are the installation steps for the required modules using pip −

pip install requests
pip install beautifulsoup4

Algorithm

The Flipkart product price tracker can be built using Python, which will keep track of the price of a particular product on Flipkart and alert the user if the price drops below a certain amount. Here are the steps to build a Flipkart product price tracker −

  • Import necessary modules − We need to import requests, re, time, and BeautifulSoup modules to build the Flipkart product price tracker.

  • Fetch the webpage − We need to fetch the webpage of the product from Flipkart using the requests module.

  • Parse the webpage − After obtaining the webpage, we must use the BeautifulSoup module to interpret it.

  • Extract the necessary information − BeautifulSoup's find() function will get the product name and price from the webpage.

  • Verify the cost − Checking whether the product's price is less than the price we intend to pay is necessary. Trigger a message if so.

  • Wait a little while − We must wait a little after checking the pricing before checking again.

Example

price-tracker.py

import os
import requests
import re
import time
from bs4 import BeautifulSoup as bs

def check_fk_price(url, amount):
   request = requests.get(url)
   soup = bs(request.content,'html.parser')

   product_name = soup.find("span",{"class":"B_NuCI"}).get_text()
   price = soup.find("div",{"class":"_30jeq3 _16Jk6d"}).get_text()
   prince_int = int(''.join(re.findall(r'\d+', price)))
   print(f"{product_name} is at {price}")
   if prince_int < amount:
      print("Book Quickly")
   else:
      print("No Slots found")


URL = "https://www.flipkart.com/apple-macbook-air-m1-8-gb-256-gb-ssd-mac-os-big-sur-mgn93hn-a/p/itmb53580bb51a7e?pid=COMFXEKMXWUMGPHW&lid=LSTCOMFXEKMXWUMGPHW40HAM7&marketplace=FLIPKART&q=macbook+air+m1&store=search.flipkart.com&srno=s_1_3&otracker=AS_Query_HistoryAutoSuggest_1_7_na_na_na&otracker1=AS_Query_HistoryAutoSuggest_1_7_na_na_na&fm=SEARCH&iid=cf486f4b-8d24-4747-8fa5-4b17cb4b3a7b.COMFXEKMXWUMGPHW.SEARCH&ppt=hp&ppn=homepage&ssid=npbt1mddr40000001622911909542&qH=be9862f704979d6e"
while True:
   check_fk_price(URL, 90000)
   time.sleep(3600)

Output

APPLE 2020 Macbook Air M1 - (8 GB/256 GB SSD/Mac OS Big Sur) MGN93HN/A  (13.3 inch, Silver, 1.29 kg) is at ₹84,490
Book Quickly

Background-runner.bat

A Python script created using the provided code creates a Flipkart product price tracker. The script retrieves the website for a specific product from Flipkart and uses the BeautifulSoup module to extract the product name and price and further notifies the user whenever the product's price falls below a certain level. After a predetermined amount of time, the script checks the product's price in an infinite loop. The best part of this is that the script runs 24/7 in the background as long as the PC stays on.

Simply execute the following simple steps to do that −

  • Open a text editor (Notepad/ VSCode)

  • Paste the below lines

"C:\Program Files\Python310\python.exe" "C:\price-tracker.py"
pause
  • Make a price-tracker.bat file and save it; make sure the file extension is.bat, not.txt. Double-click the make a price-tracker.bat file to launch the script in the background.

  • The way to the Python mediator is determined in the group content's most memorable line. Contingent upon where the Python translator is situated on your framework, this way must be changed. The second line of the batch script stops the script after it has finished running so that the user can see the results.

Applications

Each product sold on Flipkart, including phones, laptops, and other things, is eligible for usage of the site's price tracker. To track an item's worth, all you have to do is swap out the URL with the product link of the item in your wishlist. It may be used by anyone who wishes to purchase anything at a discount. Users may set up price drop notifications to alert them when a product's price drops below a predetermined level, enabling them to make wise decisions and save money.

Conclusion

This article examined how to use Python to build a Flipkart product price tracker that would alert users when a product's price dropped below a specific threshold. The tracker would keep tabs on the costs of the goods offered on the website. The value tracker may be useful if you want to cut costs on internet purchases.

Updated on: 21-Aug-2023

209 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements