A program to scrape product information from Flipkart search result pages. The script extracts product titles, prices, reviews, and links, then saves the data into a CSV file for easy analysis.
- Command-line and Interactive Modes:
- Pass all required class names and search query as command-line arguments, or
- Run interactively and enter details when prompted.
- Customizable Scraping:
Specify the class names for product titles, prices, reviews, and product links for better adaptability to Flipkart's frequently changing HTML structure. - CSV Output:
Results are saved inallProducts.csvfor convenient analysis.
- Python 3.8+
- uv (For fast and isolated package management)
- pip (for initial setup if not using
uv)
-
Install uv:
pip install uv
or follow instructions on the uv GitHub page.
-
Install dependencies using uv:
uv sync
You can run the script by passing all required parameters:
uv run main.py "<search_query>" "<title_class>" "<price_class>" "<review_class>" "<product_link_class>"Example:
uv run main.py "mobile" "4rR01T" "30jeq3" "LWZlK" "fQZEK"If you run the script without command-line arguments, it will prompt you to input:
- The search query (what you want to search for)
- The class names for title, price, reviews, and product link
uv run main.pyThen, follow the prompts.
- After the script runs, it will print the scraped data as a table.
- It will save the results in a file named
allProducts.csvin the current directory.
- Go to Flipkart and search for your desired product.
- Use your browser's developer tools (F12) to inspect the HTML elements for product titles, prices, reviews, and product links.
- Copy their class names and use them as script arguments or input.
- The script scrapes only the first page of results by default. You can modify the
rangein the script to scrape multiple pages. - Flipkart's HTML structure may change over time, so you may need to update the class names regularly.
This script is for educational purposes only.
Scraping websites may violate their Terms of Service. Use responsibly.
