Home » Python projects » Python project – price compare eCommerce

Python project – price compare eCommerce

price compare python

About the project

Compare the price of a product from multiple eCommerce sites​ using Python

In this Web scraping with Python project, the script searches for a specified product via URL (weblink) and find out the price at that moment. This is particularly useful when you want to monitor the price of the specific item (or items) from multiple eCommerce platforms. Here, in this program, we have targeted three major eCommerce website (Flipkart (owned by Walmart), Amazon and Croma) to find the price of a product (in this case iPhone X). On each execution, all three websites are crawled and the product is located, and the price is

The price of the same product from all the sources are displayed on the console window, so that buyer can see the prices and make the decision to buy from the platform which offers the lowest price. Each line of code is explained in-depth and further you can modify this script to regularly monitors the price (say 4-5 time in a day) and intimate the same through an e-mail. Look at the video to get complete information.

YouTube Video

Python code

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from pathlib import Path

source1 = "https://www.flipkart.com/apple-iphone-xs-space-grey-64-gb/p/itmf944ees7rprte?pid=MOBF944E5FTGHNCR&lid=LSTMOBF944E5FTGHNCRAH33S3&marketplace=FLIPKART&srno=s_1_2&otracker=search&otracker1=search&fm=SEARCH&iid=3bdbc1fe-fb28-4b87-b9dd-5cfa9bca72f7.MOBF944E5FTGHNCR.SEARCH&ppt=sp&ppn=sp&ssid=dh4th365ow0000001584871616021&qH=0b3f45b266a97d70"
source2 = "https://www.amazon.in/Apple-iPhone-Xs-Max-64GB/dp/B07J3CJM4N/ref=sr_1_4?dchild=1&keywords=Apple+iPhone+XS+%28Space+Grey%2C+64+GB%29&qid=1584873760&s=electronics&sr=1-4"
source3 = "https://www.croma.com/apple-iphone-xs-space-grey-64-gb-4-gb-ram-/p/214062"

# create a webdriver object for chrome-option and configure
wait_imp = 10
CO = webdriver.ChromeOptions()
CO.add_experimental_option('useAutomationExtension', False)
wd = webdriver.Chrome(r'D:\Learning\Practice\Selenium\chromedriver.exe',options=CO)
print ("*************************************************************************** \n")
print("                     Starting Program, Please wait ..... \n")

print ("Connecting to Flipkart")
f_price = wd.find_element_by_xpath("/html/body/div[1]/div/div[3]/div[2]/div[1]/div[2]/div[2]/div/div[4]/div[1]/div/div[1]")
pr_name = wd.find_element_by_xpath("/html/body/div[1]/div/div[3]/div[2]/div[1]/div[2]/div[2]/div/div[1]/h1/span")
product = pr_name.text
r_price = f_price.text
# print (r_price[1:])
print (" ---> Successfully retrieved the price from Flipkart \n")

print("Connecting to Amazon")
# a_price = wd.find_element_by_id("priceblock_ourprice")
a_price = wd.find_element_by_xpath("/html/body/div[4]/div[2]/div[4]/div[10]/div[12]/div/table/tbody/tr[2]/td[2]/span[1]")
raw_p = a_price.text
# print (raw_p[2:8])
print (" ---> Successfully retrieved the price from Amazon \n")

print("Connecting to Croma")
c_price = wd.find_element_by_xpath("/html/body/main/div[5]/div[1]/div[2]/div[2]/div/div/div[1]/div[3]/div[1]/div[2]/div[1]/div/div/span")
raw_c = c_price.text
# print (raw_c[1:7])
print (" ---> Successfully retrieved the price from Croma\n")

# Final display
print ("#------------------------------------------------------------------------#")
print ("Price for [{}] on all websites, Prices are in INR \n".format(product))
print("Price available at Flipkart is: "+r_price[1:])
print("  Price available at Amazon is: "+raw_p[2:8])
print("   Price available at Croma is: "+raw_c[1:7])

1 thought on “Python project – price compare eCommerce”

How did you like the content

Scroll to Top
%d bloggers like this: