Why Scrape Swiggy Data?
Swiggy is one of India's largest food delivery and quick-commerce platforms. For restaurant owners, cloud kitchens, and market researchers, Swiggy's platform holds invaluable competitive intelligence.
By scraping Swiggy, you can answer critical business questions:
- Competitor Pricing: How are competing restaurants pricing similar dishes in your exact delivery radius?
- Discount Strategies: What promotional coupons and flat discounts are being offered during peak hours?
- Menu Optimization: What items are marked as "Bestsellers" across top-rated restaurants?
- Market Gaps: Which cuisines have high search demand but low supply in specific PIN codes?
However, extracting this data is not as simple as parsing HTML. Swiggy is a heavily optimized Single Page Application (SPA) protected by advanced anti-bot measures.
The Challenge: Dynamic APIs and Geo-Spoofing
Swiggy does not render restaurant data in the raw HTML response. Instead, it relies on client-side React hydration fetching data from backend GraphQL and REST APIs.
Furthermore, Swiggy's content is hyper-localized. The restaurants you see depend entirely on the GPS coordinates provided in your session cookies (lat and lng). If you attempt to scrape without passing exact coordinates, the API will reject your request or return empty lists.
To successfully scrape Swiggy, you must:
- Reverse-engineer the API: Intercept the network requests in Chrome DevTools to find the exact endpoints (e.g.,
/dapi/restaurants/list/v5). - Spoof Location Headers: Accurately mock the latitude and longitude cookies to simulate a user in the target area.
- Rotate Residential Indian Proxies: Swiggy blocks AWS, DigitalOcean, and non-Indian IPs almost instantly.
Reverse-Engineering Swiggy's API (Python Example)
Instead of using Selenium to render the page (which is slow and expensive), the most efficient way to scrape Swiggy is to hit their internal APIs directly using Python's requests library.
import requests
import json
def get_swiggy_restaurants(lat, lng):
url = f"https://www.swiggy.com/dapi/restaurants/list/v5?lat={lat}&lng={lng}&is-seo-homepage-enabled=true&page_type=DESKTOP_WEB_LISTING"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
'Accept': 'application/json, text/plain, */*',
'Origin': 'https://www.swiggy.com',
'Referer': 'https://www.swiggy.com/'
}
# Swiggy requires these specific cookies for geolocation
cookies = {
'lat': str(lat),
'lng': str(lng)
}
# Use an Indian residential proxy
proxies = {
'http': 'http://username:password@in.proxy-provider.com:8000',
'https': 'http://username:password@in.proxy-provider.com:8000'
}
response = requests.get(url, headers=headers, cookies=cookies, proxies=proxies)
if response.status_code == 200:
data = response.json()
# Parse the complex JSON structure to extract restaurant nodes
return extract_restaurant_data(data)
else:
print(f"Failed to fetch data: {response.status_code}")
return None
The JSON response returned by this API is heavily nested. You will typically find the restaurant data under data.cards[X].card.card.gridElements.infoWithStyle.restaurants. The exact index changes frequently, so you should write a recursive function to search the JSON tree for keys matching infoWithStyle.
Scaling the Extraction
When you need to scrape data across an entire city (like Mumbai or Bangalore), a single coordinate is not enough. Swiggy only returns restaurants deliverable to the specific lat/lng provided.
To map a whole city, you must generate a grid of coordinates spaced approximately 3 kilometers apart, and iterate your scraper over every point in the grid. You must then deduplicate the resulting dataset, as popular restaurants will appear in multiple overlapping grid searches.
This requires a robust scraping pipeline with task queues (like Celery), distributed workers, and intelligent proxy rotation to avoid rate limits.
If building and maintaining this infrastructure sounds daunting, DataScraper provides managed Swiggy scraping services. We handle the proxies, API changes, and geo-mapping, delivering clean, deduplicated data directly to your database or Excel file within 48 hours.