Google Shopping aggregates product listings from thousands of merchants into a structured comparison format. Extracting this data at scale is valuable for price intelligence platforms, competitive monitoring, and catalog enrichment. The Scavio API returns Google Shopping results in the shopping_results field with product title, price, merchant name, rating, review count, image URL, and product link. This tutorial builds a structured data extraction pipeline that queries Google Shopping for product categories and normalizes the output for analytics.
Prerequisites
- Python 3.8 or higher
- requests library installed
- A Scavio API key
- Product categories or specific products to monitor
Walkthrough
Step 1: Fetch Google Shopping results
Query the Scavio endpoint for a product. Shopping results appear in the shopping_results array of the response.
def get_shopping_data(product: str) -> list[dict]:
r = requests.post(
"https://api.scavio.dev/api/v1/search",
headers={"x-api-key": API_KEY},
json={"query": product, "country_code": "us"}
)
r.raise_for_status()
return r.json().get("shopping_results", [])Step 2: Normalize the shopping data
Transform raw shopping results into a consistent schema with parsed price values for analysis.
def normalize_item(item: dict) -> dict:
price_str = item.get("price", "")
price = float(price_str.replace("$", "").replace(",", "")) if price_str else None
return {
"title": item.get("title", ""),
"price": price,
"price_raw": price_str,
"merchant": item.get("source", ""),
"rating": float(item.get("rating", 0) or 0),
"reviews": int(item.get("reviews", 0) or 0),
"link": item.get("link", ""),
"thumbnail": item.get("thumbnail", ""),
}Step 3: Compute price statistics
Calculate min, max, median, and average prices across all merchants for a product.
import statistics
def price_stats(items: list[dict]) -> dict:
prices = [i["price"] for i in items if i["price"] is not None]
if not prices:
return {"min": None, "max": None, "median": None, "mean": None}
return {
"min": min(prices),
"max": max(prices),
"median": statistics.median(prices),
"mean": round(statistics.mean(prices), 2),
}Step 4: Export structured feed
Write the normalized shopping data to a JSON file suitable for ingestion by analytics tools or databases.
import json
def export_feed(product: str, items: list[dict]) -> None:
feed = {
"product": product,
"item_count": len(items),
"stats": price_stats(items),
"items": items,
}
with open(f"shopping_{product.replace(' ', '_')}.json", "w") as f:
json.dump(feed, f, indent=2)
print(f"Exported {len(items)} items for {product}")Python Example
import os
import json
import statistics
import requests
API_KEY = os.environ.get("SCAVIO_API_KEY", "your_scavio_api_key")
ENDPOINT = "https://api.scavio.dev/api/v1/search"
def get_shopping(product: str) -> list[dict]:
r = requests.post(ENDPOINT, headers={"x-api-key": API_KEY},
json={"query": product, "country_code": "us"})
r.raise_for_status()
return r.json().get("shopping_results", [])
def normalize(item: dict) -> dict:
p = item.get("price", "")
return {
"title": item.get("title"), "price": float(p.replace("$", "").replace(",", "")) if p else None,
"merchant": item.get("source"), "rating": item.get("rating"), "reviews": item.get("reviews"),
}
if __name__ == "__main__":
items = [normalize(i) for i in get_shopping("mechanical keyboard")]
prices = [i["price"] for i in items if i["price"]]
print(f"Found {len(items)} listings")
if prices:
print(f"Price range: ${min(prices):.2f} - ${max(prices):.2f}")
print(f"Median: ${statistics.median(prices):.2f}")
for i in sorted(items, key=lambda x: x["price"] or float("inf"))[:5]:
print(f" {i['merchant']}: ${i['price']:.2f} - {i['title'][:50]}")JavaScript Example
const API_KEY = process.env.SCAVIO_API_KEY || "your_scavio_api_key";
const ENDPOINT = "https://api.scavio.dev/api/v1/search";
async function getShopping(product) {
const res = await fetch(ENDPOINT, {
method: "POST",
headers: { "x-api-key": API_KEY, "Content-Type": "application/json" },
body: JSON.stringify({ query: product, country_code: "us" })
});
const data = await res.json();
return (data.shopping_results || []).map(i => ({
title: i.title, price: i.price ? parseFloat(i.price.replace(/[$,]/g, "")) : null,
merchant: i.source, rating: i.rating
}));
}
async function main() {
const items = await getShopping("mechanical keyboard");
const prices = items.map(i => i.price).filter(Boolean);
console.log(`${items.length} listings, $${Math.min(...prices)} - $${Math.max(...prices)}`);
items.sort((a, b) => (a.price || Infinity) - (b.price || Infinity)).slice(0, 5)
.forEach(i => console.log(` ${i.merchant}: $${i.price} - ${i.title?.slice(0, 50)}`));
}
main().catch(console.error);Expected Output
Found 15 listings
Price range: $39.99 - $299.99
Median: $89.99
Amazon: $39.99 - Redragon K552 Mechanical Gaming Keyboard
Walmart: $49.99 - RK ROYAL KLUDGE RK61 60% Mechanical
Best Buy: $74.99 - HyperX Alloy Origins Core Mechanical