惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
博客园 - 叶小钗
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
腾讯CDC
S
SegmentFault 最新的问题
D
DataBreaches.Net
Hugging Face - Blog
Hugging Face - Blog
L
LangChain Blog
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
N
Netflix TechBlog - Medium
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 三生石上(FineUI控件)
F
Fortinet All Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Martin Fowler
Martin Fowler
雷峰网
雷峰网
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
小众软件
小众软件
云风的 BLOG
云风的 BLOG
T
Tailwind CSS Blog

SerpApi

SerpApi Weekly Changelog: Sep 07 - 13, 2026 Introducing MCP Bundle Support for SerpApi SerpApi Weekly Changelog: Aug 31 - Sep 06, 2026 We Have Resolved the Google /goto URL Redirect Rollout How to scrape Zillow Reddit promised its users an open internet. Then it closed the door. SerpApi Weekly Changelog: August 24 - 30, 2026 Best web scraping tools in 2026 Google’s New /goto Redirect URLs: Resolution in Progress How to Scrape Walmart Reviews Results Understanding HTTP 429: Too Many Requests Google tried again. We’re moving to dismiss a second time. SerpApi Weekly Changelog: August 17 - 23, 2026 Introducing SerpApi's New Markdown Output SerpApi Surpasses 1.5 Million Activated User Accounts How a Lead Generation Company Scaled Outreach with SerpApi's Google Maps API SerpApi Weekly Changelog: August 10 - 16, 2026 How to scrape book results from the Google Play Store What is an API? Part 3: Dynamic Data Displays with D&D! We Filed an Amicus Brief in U.S. v. Google How to scrape Google Play Store game information SerpApi Weekly Changelog: August 03 - 09, 2026 Introducing SerpApi Search Tools: Real-Time Web Search for Python AI Agents Measuring World Cup Attention: What the data says about Vozinha SerpApi Weekly Changelog: July 27 - August 02, 2026 How to Scrape Google Maps Autocomplete Build an AI Event Discovery Agent That Adds Events to Your Calendar in One Click How to Aggregate Local Business Ratings-Without Averaging DataForSEO vs. SerpApi Why is Ruby on Rails a great fit for AI agents
Track and Compare Product Prices Across Stores and Locati...
Autumrose Stubbs · 2026-06-12 · via SerpApi

In modern e-commerce, pricing changes constantly across retailers and depends where you are located. This makes it difficult to track product value in real time. In this blog we'll review how to build a multi-store price tracking system across the globe, using SerpApi and Python.

Pull structured search data from Amazon, Walmart, Target, CVS, and more. Using this data you can monitor product prices, compare competitors, and maintain a continuously updated view of the market.

Getting Started with SerpApi

If you are new to SerpApi get started with this blog post:

Getting started with SerpApi: The Web Search API

Learn what SerpApi is, how to use it, and why you need it.

SerpApiHilman Ramadhan

Now that you are setup with SerpApi and have located your API key, let's take a look at SerpApi's libraries.

Libraries

In this example we will be using SerpApi's Python library.

To install the serpapi package, simply run the following command:

$ pip install serpapi

You can also make a simple GET request or for other programming languages, view our supported libraries here: https://serpapi.com/integrations.

Using SerpApi you can automatically gather product data across multiple stores and normalize it into a structured format. The goal is to build a tool that can:

  • Track a product across multiple retailers (e.g., Amazon, Walmart, Target, etc.)
  • Track a product across multiple locations
  • Support use cases like alerts, dashboards, or competitive analysis

SerpApi offers many different shopping APIs. For this example we will be using:

Amazon

  • Amazon Search API
    • Collect search results for a specific keyword.
    • Each result has the asin value for a specific product.
    • If you already have product asin values, skip this step.
  • Amazon Product API
    • Scrape full product page for a specific product using the asin value.

Walmart

  • Walmart Search API
    • Collect search results for a specific keyword.
    • Each result has the product_id value for a specific product.
    • If you already have product product_id values, skip this step.
  • Walmart Product API
    • Scrape full product page for a specific product using the product_id value.

Google Shopping (Additional Retailers)

  • Google Shopping API
    • Collect search results for a specific keyword.
    • Each result has the immersive_product_page_token value for a specific product.
    • If you already have product immersive_product_page_token values, skip this step.
  • Google Immersive Product API
    • There we can get the prices for many different stores.

Additional Shopping APIs

While SerpApi offers many additional APIs, this tutorial will focus on the three mentioned above.

For a complete list of available APIs, see the full documentation here:

Search engine APIs

Explore all of our search engine APIs for real-time search data

SerpApi

Price Comparison Steps

In this example we already have a product selected, including the Amazon asin, Walmart product_id, and name. As well as the location details needed to track different areas.

1. Set Target Stores

We start by specifying a list of stores we want to monitor. This allows us to control coverage and easily expand or reduce retailer tracking. In this case we are tracking:

target_stores = ["amazon","walmart", "target", "walgreens", "cvs"]

If you have additional target stores, you can easily add them to this list to track them as well.

2. Load Input Data

Read in a CSV file (products_input.csv) containing the Amazon asin, Walmart product_id, name, and location details.

My CSV:

name,asin,walmart_id,walmart_store,zip_code,state,country,country_code
M&M's Minis Milk Chocolate Candy Sharing,B09RBG3NWB,805902256,4554,78757,Texas,United States,US
M&M's Minis Milk Chocolate Candy Sharing,B09RBG3NWB,805902256,2568,91402,California,United States,US
M&M's Minis Milk Chocolate Candy Sharing,B09RBG3NWB,805902256,5293,11096,New York,United States,US
M&M's Minis Milk Chocolate Candy Sharing,B09RBG3NWB,805902256,5350,84117,Utah,United States,US

If you don't have your products' asin or walmart_id, you can collect these values using the Amazon Search API and the Walmart Search API.

Blogs to get started with either:

How to Scrape Walmart in 2026 (Complete guide)

Learn how to scrape Walmart product listings, extract product details, and collect customer reviews using SerpApi’s Walmart APIs. This step-by-step tutorial covers Python and JavaScript examples for retrieving structured Walmart data without maintaining scrapers.

SerpApiArtur Chukhrai

3. Initialize Structured Store Data

For each product, we create a standardized stores dictionary structure per store, initializing fields like:

  • price
  • search_id

There are many other data pieces returned in the results we can also include, however in this example we are just looking at the pricing.

4. Query SerpApi Per Product/Store Combination

We loop through each product and query SerpApi to retrieve search results for each location and all the stores available.

  • Amazon Product API - using the asin value as input
  • Walmart Product API - using the Walmart product_id
  • Google Shopping API - using the name
    • Google Immersive Product API - iterate through all the stores and collect the data for the relevant sellers.

5. Export or Extend the Output

Finally, the processed data can be:

  • Exported to CSV
  • Stored in a database
  • Used in dashboards
  • Extended into alerting/monitoring systems

In this example we'll export to a new CSV with the timestamp in the title.

Code

import serpapi 
import csv
from datetime import datetime

API_KEY = "YOUR_SECRET_API_KEY"

target_stores = ["amazon","walmart", "target", "walgreens", "cvs"]

# Query the Amazon Product API 
# Input parameters from the input CSV including asin, zip, and country
# Return Search ID and price
def amazon_search(asin, zip, country):
	search_id = ""
	price = ""

	# Query Amazon Product API using the asin value
	params = {
		"api_key": API_KEY,
		"engine": "amazon_product",
		"asin": asin,
		"delivery_zip": zip, 
		"shipping_location": country
	}

	results = serpapi.search(params).as_dict()

	# Check if required price fields are available
	if "product_results" in results:
		search_id = results["search_metadata"]["id"]
		amazon_product = results["product_results"] 
		if "price" in amazon_product:
			price = amazon_product["price"]
		else:
			price = "Unavailable"

	return search_id, price


# Query the Walmart Product API 
# Input parameters from the input CSV including the Walmart product ID and store ID
# Return Search ID and price
def walmart_search(walmart_id, store_id):
	search_id = ""
	price = ""
	# Query Walmart Product API using the product ID
	params = {
		"api_key": API_KEY,
		"engine": "walmart_product",
		"product_id": walmart_id,
		"store_id": store_id
	}

	walmart_results = serpapi.search(params).as_dict()

	# Check if required fields are available

	if "product_result" in walmart_results:
		search_id = walmart_results["search_metadata"]["id"]
		walmart_product = walmart_results["product_result"]
		if "price_map" in walmart_product:
			price = walmart_product["price_map"]["price"]
		else:
			price = "Unavailable"

	return search_id, price

# Query the Amazon Product API 
# Input parameters from the input CSV including asin, zip, and country
# Set applicable values in the global stores dictionary 
def google_shopping(product_name, location, country):
	addl_results = {}
	# Query the Google Shopping API using the product name extracted from the Walmart or Amazon Product APIs
	params = {
		"api_key": API_KEY,
		"engine": "google_shopping",
		"q": product_name,
		"location": location,
		"gl": country
	}

	shopping_results = serpapi.search(params).as_dict()

	# Verify there are shopping results available
	if "shopping_results" in shopping_results:
		google_shop_results = shopping_results["shopping_results"]

		if len(google_shop_results) > 0:

			# Set token to query the Google Immersive Product API from Google Shopping results
			immersive_product_token = shopping_results["shopping_results"][0]["immersive_product_page_token"]
			# Copy target stores to a set to track what we have found (already found Amazon and Walmart)
			remaining_stores = set(target_stores) - {"amazon", "walmart"}			
			# Token for next page of store results for a product
			next_page = ""

			# Iterate through Google Immersive Product results until there are no more stores in the results or target
			while True:
				params = {
					"api_key": API_KEY,
					"engine": "google_immersive_product",
					"page_token": immersive_product_token,
					"more_stores": "true",
					"next_page_token": next_page
				}
				immersive_results = serpapi.search(params).as_dict()

				# Check if there are product results within the results 
				if "product_results" in immersive_results:
					immersive_product = immersive_results["product_results"]

					# Check if there are stores within the product results
					if "stores" in immersive_product:
						stores_results = immersive_product["stores"]
						
						# Iterate through the stores available
						for store in stores_results:

							# Normalize and check if the store matches one of our target stores
							store_name = store["name"].lower().replace("'", "").replace(" ", "")
							match = next((s for s in remaining_stores if s in store_name), None)

							#If there's a match add the product details to our result dictionary
							if match:
								addl_results[match] = {
    								"price": store.get("price", "No Results"),
   									"search_id": immersive_results["search_metadata"]["id"]
								}
								# Remove match from the remaining target stores set
								remaining_stores.remove(match)

					# Assign next page token if it's available 
					if "stores_next_page_token" in immersive_product:
						next_page = immersive_product["stores_next_page_token"]
					# Otherwise break out of the loop (no more stores in results)
					else:
						break
				else:
					break
				# Break out of the loop if there are no more target stores remaining
				if not remaining_stores:
					break
	return addl_results	

# Write results out to a CSV file
def write_to_csv(rows, output_prefix="products_output"):
    flat_rows = []

    # Original input columns first
    input_columns = list(rows[0].keys())
    input_columns.remove("stores")

    # Store columns in desired order
    store_columns = []

    for store in target_stores:
        store_columns.extend([
            f"{store}_search_id",
            f"{store}_price"
        ])

    for row in rows:
        flat_row = {}

        # Add original CSV fields first
        for col in input_columns:
            flat_row[col] = row.get(col, "")

        # Add store fields in consistent order
        stores = row.get("stores", {})

        for store in target_stores:
            data = stores.get(store, {})

            flat_row[f"{store}_search_id"] = data.get("search_id", "")
            flat_row[f"{store}_price"] = data.get("price", "")

        flat_rows.append(flat_row)

    fieldnames = input_columns + store_columns

    timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
    output_file = f"{output_prefix}_{timestamp}.csv"

    with open(output_file, "w", newline="", encoding="utf-8") as outfile:
        writer = csv.DictWriter(outfile, fieldnames=fieldnames)
        writer.writeheader()
        writer.writerows(flat_rows)

def main():
	with open("products_input.csv", "r", newline="", encoding="utf-8") as infile:
		reader = csv.DictReader(infile)
		rows = list(reader)

		# Iterate through each row of the CSV
		for row in rows:
			stores = { 
				store: { "price": "No Results", "unit": "No Results", "search_id": "" } 
				for store in target_stores 
			}
			search_id, price = amazon_search(row["asin"], row["zip_code"], row["country"])
			stores["amazon"] = {"price": price, "search_id": search_id}

			search_id, price = walmart_search(row["walmart_id"], row["walmart_store"])
			stores["walmart"] = {"price": price, "search_id": search_id}

			stores.update(google_shopping(row['name'], f"{row['zip_code']},{row['state']},{row['country']}", row["country_code"]))
			row["stores"] = stores
	write_to_csv(rows)

if __name__ == "__main__":
	main()

Result Values

Within the results you will see 3 different pricing options, including:

An actual price

  • The product was found
  • The product has pricing details for the specified locaton
  • Ex: $3.58

"No Results"

  • The product was not found
  • The product doesn't have this seller listed in the location specified

"Unavailable"

  • The item was found however there was no pricing available
  • Ex: the product may not be available for sale in the selected location or sold out

For example in Amazon, this product was found however there is no pricing available for the specified location:

Now that we've identified the results structure, let's take a look at the results for this example.

Results

For visualization I have uploaded the returned CSV into Google Sheets with the input values highlighted gray and the price values highlighted yellow:

You can see the variance in pricing across stores and locations even for this 1 product across 4 different locations.

You can use this data to compare pricing across different locations, track competitor pricing, and much more!

Conclusion

Using SerpApi makes comparing product prices across different stores and locations effortless. While this example focused primarily on pricing data, the shopping / product APIs provide access to many other valuable data points, including product ratings, review counts, shipping details, availability, seller information, and more.

Additionally, the Google Immersive Product API supports a wide range of retailers outside of this target list, with available stores varying by country and region.

By combining data from multiple shopping sources and locations, organizations can build comprehensive price intelligence solutions, automate competitive analysis, and make more informed decisions based on real-time market data. Whether you're monitoring competitors, optimizing pricing strategies, conducting market research, or tracking product availability, SerpApi provides a flexible and scalable foundation for collecting and analyzing e-commerce data.

Resources