#!/usr/bin/env python3 """ Test script to verify the Flipkart scraper functionality """ import asyncio import sys import os # Add the current directory to Python path to import our modules sys.path.append(os.path.dirname(os.path.abspath(__file__))) from flipkart_scraper import scrape_flipkart_price_and_name async def test_flipkart_scraper(): """Test the Flipkart scraper with a sample URL""" # Test URL - using the provided Flipkart water purifier URL test_url = "https://www.flipkart.com/kenstar-black-pureza-8-l-ro-uf-uv-copper-alkaline-mineralizer-water-purifier-needs-no-service-2-years/p/itm123f0d1974f36?pid=WAPHBA97RGPHMG26&lid=LSTWAPHBA97RGPHMG26W1HS33&marketplace=FLIPKART&store=j9e%2Fabm%2Fi45&spotlightTagId=default_FkPickId_j9e%2Fabm%2Fi45&srno=b_1_3&otracker=browse&fm=organic&iid=86c6987c-eee9-4a61-bfb0-bb03a0e1d22b.WAPHBA97RGPHMG26.SEARCH&ppt=browse&ppn=browse&ssid=y2x15jcn740000001758288207739" print(f"Testing Flipkart scraper with URL: {test_url}") print("-" * 50) try: # Test combined extraction print("Extracting price and product name...") product_name, price = await scrape_flipkart_price_and_name(test_url) if price: print(f"✓ Price extracted successfully: ₹{price}") else: print("✗ Failed to extract price") if product_name: print(f"✓ Product name extracted successfully: {product_name}") else: print("✗ Failed to extract product name") print("\n" + "=" * 50) if price and product_name: print("🎉 SUCCESS: Both price and product name extracted successfully!") print(f"Product: {product_name}") print(f"Price: ₹{price}") else: print("❌ FAILED: Could not extract all required information") except Exception as e: print(f"❌ ERROR: {e}") if __name__ == "__main__": # Run the test asyncio.run(test_flipkart_scraper())