Skip to main content
Create a complete price monitoring system from scratch to track price changes on e-commerce sites like Amazon. This step-by-step guide walks you through building an automated system that scrapes, stores, and monitors price data.

Who Is this for?

This guide is designed for developers who want to build a price monitoring system from the ground up using web scraping. No existing price monitoring infrastructure required.

What you’ll learn

  • Extract product price data from an Amazon product page using ZenRows.
  • Clean the extracted raw data and structure it for storage and price monitoring.
  • Store price history with timestamps.
  • Schedule automated scraping at regular intervals.
  • Set up price change notifications.
  • Optimize performance and manage costs.

Step 1: Set Up Data Extraction

Extract specific product data related to pricing, availability, and social cues using ZenRows css_extractor. Stringify the css_extractor for compatibility:
Python
Define a scraper function to extract data from a product URL based on the css_extractor.
CSS selectors can change when websites update their code. To maintain a reliable scraper, monitor your selectors regularly and update them as needed. Learn more about CSS selectors here.
The js_render parameter handles the site’s dynamic rendering, while premium_proxy routes the request through premium proxies to avoid blocking. proxy_country is set to us to send requests from US-based IP addresses:
Python
The proxy_country parameter is optional. If not specified, ZenRows will use a random IP address worldwide. See more about geolocation here.
Execute the scraper function and print the extracted raw data. Here’s the updated code:
Python
The code returns the required data from the product page. Here’s what it looks like:
JSON response

Step 2: Clean and Structure the Data

The returned data is unsuitable for price monitoring in its current state since it contains undesired strings. Since some fields are returned as a list, define a consistency_handler to handle them as a list before cleaning:
Python
Define a function to obtain the current price (discounted), the original price, and the discount percentage from the price field:
Python
Clean the reviewCount field by extracting the count integer from the list of strings:
Python
Obtain the average_rating as a float from the raw data:
Python
Similarly, parse the estimated number of units sold from the demandHistory field:
Python
Clean the availability field by extracting the In Stock string from the strings:
Python
Finally, parse the cleaned data as a separate dictionary. Use datetime and timestamp to get the timestamp of the scraping operation to track historical data:
Python
Apply the parse_cleaned_data to the raw_data to get a cleaned version with a recorded timestamp:
Python
Here’s a sample of the cleaned data:
JSON

Step 3: Store the Price History Data

Since the scraping will be scheduled, start the storage procedure by setting up logging to track the extraction process in real-time:
Python
Define a function to create a new price record for each scraping request and store it in a product_history.json file. Index the stored data by product name:
Python
Set up an alert trigger (alert_triggered=False) and check for price changes by comparing the previously scraped price to the current one. Set alert_triggered to True if a price change is detected. Then, log the price difference. Append new price records with existing ones in the JSON file. If a product doesn’t exist in the JSON file, create a new record for it:
Python
Finally, update the existing records with the new pricing records and return the alert status:
Python
Here’s the complete update_and_save_price_history function:
Python

Step 4: Create a Scraping Job

Create a job function to execute the extraction, data cleaning, and storage logics. This function logs the scraping timestamps and price change notifications:
Python

Step 5: Schedule the Scraping Job

Schedule the extraction process using Python’s schedule module. The code below runs the scraping job every 30 seconds and checks for jobs every second:
Python

Step 6: Put Everything Together

Here’s the complete code:
Python
The code initiates a scheduled scraping process, extracts price data every 30 seconds, and mocks an alert for price changes. Below is a sample of data for two schedules from the price_history JSON file:
JSON
Here’s a sample log to track price changes and scraping intervals for the two records:
Congratulations! 🎉 You’ve built a price monitoring system using ZenRows as the scraping solution.

Next Steps: Enhance Your System

Add Email Notifications

Set up email alerts when prices change:
Python

Monitor Multiple Products

Track multiple products by modifying the monitoring function:
Python

Database Integration

Replace JSON storage with a database for better performance:
Python

Troubleshooting

Missing Data

  • Enable js_render for dynamic content
  • Increase wait time for slow-loading pages or consider switching to wait_for
  • Verify if the CSS selectors are correct

Rate Limiting

  • Use premium_proxy for residential IPs
  • Add delays between requests
  • Monitor your API usage

Selector Changes

  • Test selectors regularly
  • Use more stable selectors when possible
  • Implement fallback selectors

Best Practices

  • Monitor selector stability: Check if your CSS selectors still work monthly
  • Handle errors gracefully: Always include try-catch blocks for network requests
  • Log everything: Comprehensive logging helps debug issues
  • Start small: Begin with one product before scaling to multiple products
  • Respect rate limits: Don’t overwhelm target websites with too many requests