Python Project – Price Comparison Extension

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

  • Develop a tool for comparing product prices across multiple e-commerce websites.
  • Implement a user-friendly interface for entering product names and displaying the scraping process.
  • Automate the web scraping process to gather product information from Amazon, Flipkart, and eBay.
  • Save the gathered data into a CSV file for further analysis.

Project Setup

Required Libraries

  • Selenium: For web scraping and browser automation.
  • Pandas: For data manipulation and analysis.
  • webdriver-manager: For managing browser drivers.
  • Tkinter: For building the graphical user interface.

Prerequisites for Python Price Comparison Extension

  • Basic understanding of Python programming.
  • Familiarity with web scraping concepts using Selenium.
  • Understanding of Tkinter for GUI development.

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

  • time: It introduces delays in the web scraping process to allow pages to load.
  • Pandas: It is used for data manipulation and saving scraped data.
  • Selenium and related imports: Used for automating web browser interactions.
  • Tkinter and messagebox: Used for creating a graphical user interface.
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

  • This function initiates the scraping process, taking product_name as an argument.
  • The webdriver.Chrome( ) sets up the Chrome WebDriver using webdriver_manager to manage driver installations.
  • urls is a dictionary containing search URLs for Amazon, Flipkart, and eBay.
  • Scrape_amazon: This function scrapes data from the search results page of the specified product on Amazon.
  • scrape_flipkart: This function scrapes data from the Flipkart site’s search result page for the specified product.
  • scrape_ebay: This function scrapes data from the eBay site’s search result page for the specified product.
  • The above functions call each scraping function to gather data.
  • driver.quit(): Closes the web browser.
  • df = pd.DataFrame(results): This converts the results list into a Pandas DataFrame.
  • Finally, it is saved to a CSV file using df.to_csv().
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

  • get_product_name() function gets the product name from the user input.
  • Then retrieves the product name from the input entry, and if the product name is not empty, then it calls the start_scraping function
  • root = tk.Tk(): It initializes the main Tkinter window.
  • tk.Button( ): It creates a button that, when clicked, calls the get_product_name function to start the scraping process.
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

price comparison interface

2. Scraping Site 1

scraping site1

3. Scraping Site 2

scraping site2

4. Scraping Site 3

scraping site3

5. Comparison Completed

comparison completed

6. Price Comparison Results

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.