Walmart is the second-largest e-commerce platform in the United States, making it essential for price comparison tools, retail analytics, and competitive intelligence. Scraping Walmart directly is blocked aggressively. The Scavio API provides a stable Walmart search endpoint that returns product listings including title, price, rating, review count, seller info, and availability. This tutorial demonstrates how to search for products, extract pricing data, and build a simple product listing.
Prerequisites
- Python 3.8 or higher
- requests library installed
- A Scavio API key
- Familiarity with REST API calls and JSON
Walkthrough
Step 1: Send a Walmart product search
POST to the Scavio endpoint with platform walmart and your search query. The response contains a list of product results.
def search_walmart(query: str) -> dict:
response = requests.post(
"https://api.scavio.dev/api/v1/search",
headers={"x-api-key": API_KEY},
json={"platform": "walmart", "query": query}
)
response.raise_for_status()
return response.json()Step 2: Extract product listings
The products key contains a list of product objects. Each has title, price, rating, reviews, and availability.
data = search_walmart("wireless headphones")
products = data.get("products", [])
print(f"Found {len(products)} products")Step 3: Sort by price
Parse the price field and sort products to find the cheapest options. Prices may include currency symbols, so strip them before converting.
def parse_price(p: str) -> float:
return float(p.replace("$", "").replace(",", "")) if p else float("inf")
sorted_products = sorted(products, key=lambda x: parse_price(x.get("price", "")))
for p in sorted_products[:5]:
print(f"{p['title'][:50]} — {p['price']}")Step 4: Save results to JSON
Persist the product data to a JSON file for downstream processing or comparison.
import json
with open("walmart_results.json", "w") as f:
json.dump(products, f, indent=2)
print("Saved to walmart_results.json")Python Example
import os
import json
import requests
API_KEY = os.environ.get("SCAVIO_API_KEY", "your_scavio_api_key")
ENDPOINT = "https://api.scavio.dev/api/v1/search"
def search_walmart(query: str) -> list[dict]:
r = requests.post(ENDPOINT, headers={"x-api-key": API_KEY},
json={"platform": "walmart", "query": query})
r.raise_for_status()
return r.json().get("products", [])
def cheapest(products: list[dict], n: int = 5) -> list[dict]:
def price(p):
s = p.get("price", "")
return float(s.replace("$", "").replace(",", "")) if s else float("inf")
return sorted(products, key=price)[:n]
if __name__ == "__main__":
products = search_walmart("wireless headphones")
for p in cheapest(products):
print(f"{p['title'][:50]} — {p.get('price', 'N/A')} ({p.get('rating', 'N/A')} stars)")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 searchWalmart(query) {
const res = await fetch(ENDPOINT, {
method: "POST",
headers: { "x-api-key": API_KEY, "Content-Type": "application/json" },
body: JSON.stringify({ platform: "walmart", query })
});
const data = await res.json();
return data.products || [];
}
function parsePrice(str) {
return str ? parseFloat(str.replace(/[$,]/g, "")) : Infinity;
}
async function main() {
const products = await searchWalmart("wireless headphones");
const sorted = products.sort((a, b) => parsePrice(a.price) - parsePrice(b.price));
sorted.slice(0, 5).forEach(p => console.log(`${p.title.slice(0, 50)} — ${p.price}`));
}
main().catch(console.error);Expected Output
{
"products": [
{
"title": "Sony WH-1000XM5 Wireless Headphones",
"price": "$279.00",
"rating": "4.8",
"reviews_count": 12847,
"availability": "In Stock",
"seller": "Walmart.com",
"url": "https://walmart.com/ip/sony-wh1000xm5/..."
}
]
}