Site icon TechVidvan

Python Project – Price Comparison Extension

python price comparison extension project

The Price Comparison Extension is a Python-based application designed to compare product prices across multiple e-commerce websites. This project aims to provide users with an easy-to-use tool to find the best prices for their desired products on popular online platforms such as Amazon, Flipkart, and eBay. The application utilises web scraping techniques and presents the results in a CSV file for further analysis.

About Python Price Comparison Extension

The Price Comparison Extension project leverages web scraping to gather product prices from various e-commerce websites. By inputting the product name into a Tkinter-based graphical user interface (GUI), users can initiate the scraping process and retrieve price information from Amazon, Flipkart, and eBay. The results are saved into a CSV file for easy access and comparison.

Objectives of Python Price Comparison Extension

Project Setup

Required Libraries

Prerequisites for Python Price Comparison Extension

Download the Python Price Comparison Extension Project

Please download the source code of the Python Price Comparison Extension Project: Python Price Comparison Extension Project Code.

Step-by-Step Code Implementation of Python Price Comparison Extension

1. Importing Libraries

import time
import pandas as pd
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
import tkinter as tk
from tkinter import messagebox

2. Scraping Function

def start_scraping(product_name):
   driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))


   urls = {
       "Amazon": f"https://www.amazon.in/s?k={product_name}",
       "Flipkart": f"https://www.flipkart.com/search?q={product_name}",
       "eBay": f"https://www.ebay.com/sch/i.html?_nkw={product_name}"
   }


   results = []


   def scrape_amazon():
       driver.get(urls["Amazon"])
       time.sleep(3)
       products = driver.find_elements(By.XPATH, "//div[@data-component-type='s-search-result']")
       for product in products[:5]:
           title = product.find_element(By.TAG_NAME, "h2").text
           try:
               price = product.find_element(By.CLASS_NAME, "a-price-whole").text
           except:
               price = "N/A"
           results.append({"Website": "Amazon", "Title": title, "Price": price})


   def scrape_flipkart():
       driver.get(urls["Flipkart"])
       time.sleep(3)
       products = driver.find_elements(By.CLASS_NAME, "_1AtVbE")
       for product in products[:5]: 
           try:
               title = product.find_element(By.CLASS_NAME, "IRpwTa").text
               price = product.find_element(By.CLASS_NAME, "_30jeq3").text
               results.append({"Website": "Flipkart", "Title": title, "Price": price})
           except:
               continue


   def scrape_ebay():
       driver.get(urls["eBay"])
       time.sleep(3)
       products = driver.find_elements(By.CLASS_NAME, "s-item")
       for product in products[:5]:
           try:
               title = product.find_element(By.CLASS_NAME, "s-item__title").text
               price = product.find_element(By.CLASS_NAME, "s-item__price").text
               results.append({"Website": "eBay", "Title": title, "Price": price})
           except:
               continue


   scrape_amazon()
   scrape_flipkart()
   scrape_ebay()


   driver.quit()


   df = pd.DataFrame(results)
   df.to_csv("price_comparison_results.csv", index=False)


   messagebox.showinfo("Info", "Comparison completed and results saved to price_comparison_results.csv")

3. Tkinter Interface

def get_product_name():
   product_name = entry.get()
   if product_name:
       start_scraping(product_name)
   else:
       messagebox.showerror("Input Error", "Please enter a product name")


root = tk.Tk()
root.title("TechVidvan@Price Comparison Extension")


tk.Label(root, text="Enter Product Name:").pack(pady=10)
entry = tk.Entry(root)
entry.pack(pady=5)


tk.Button(root, text="Start Scraping", command=get_product_name).pack(pady=20)


root.mainloop()

Python Price Comparison Extension Output

1. Application Interface

2. Scraping Site 1

3. Scraping Site 2

4. Scraping Site 3

5. Comparison Completed

6. Price Comparison Results

Conclusion

The Price Comparison Extension project successfully integrates web scraping with a user-friendly interface built with Tkinter. It provides a practical tool for comparing product prices across multiple e-commerce websites, helping users find the best deals and make informed purchasing decisions.

Exit mobile version