Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimitryzub/31252bd851db23ac046df6e63d8bf0eb to your computer and use it in GitHub Desktop.
Save dimitryzub/31252bd851db23ac046df6e63d8bf0eb to your computer and use it in GitHub Desktop.
How to search for 1 specific product by SKU/UPC across all Walmart Store IDs
from serpapi import GoogleSearch
import pandas as pd
import json, os
walmart_store_ids = pd.read_json("serpapi-walmart-store-ids.json") # 4,640 stores
for store_id in walmart_store_ids["store_id"]:
params = {
"api_key": os.getenv("API_KEY"), # your serpapi api key
"engine": "walmart_product", # search engine
"product_id": "274388920", # https://www.walmart.com/ip/LEGO-The-First-Adventure-21169-Building-Set-542-Pieces/274388920?athbdg=L1800
"store_id": store_id # 1158, 726, 2739...
}
search = GoogleSearch(params)
results = search.get_dict()
city = results.get("search_information", {}).get("location", {}).get("city")
province_code = results.get("search_information", {}).get("location", {}).get("province_code")
postal_code = results.get("search_information", {}).get("location", {}).get("postal_code")
product_data = {
"store_id": store_id,
"address": f"{city}, {province_code}, {postal_code}",
"product_title": results.get("product_result", {}).get("title"),
"product_price": results.get("product_result", {}).get("price_map", {}).get("price"),
"is_in_stock": results.get("product_result", {}).get("in_stock"),
"product_reviews": results.get("product_result", {}).get("reviews"),
"product_rating": results.get("product_result", {}).get("rating"),
"product_id": results.get("product_result", {}).get("product_id"),
}
print(json.dumps(product_data, indent=2, ensure_ascii=False))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment