ProxyForge Download

Automated Price Monitoring in Python: Proxies, Alerts, and Scale

Introduction

Automated price monitoring is a critical task for businesses and developers looking to track prices of products across various platforms like Amazon, eBay, and Google Shopping. This guide will walk you through setting up an end-to-end price monitoring system using Python. We'll cover scheduled requests with APScheduler, proxy rotation with failure handling, using geo-targeted residential proxies from providers like Bright Data and SmartProxy for location-accurate prices, storing data in SQLite, and sending alerts via Telegram or email when price thresholds are breached.

Setting Up the Environment

Before we dive into the code, ensure you have Python installed on your system. You'll also need to install several packages:

pip install requests apscheduler sqlite3 python-telegram-bot

Step 1: Fetching Prices with Requests and Proxies

We'll start by fetching prices from a sample website using requests. To handle multiple websites, we can create a function that takes the URL and returns the price.

import requests

def fetch_price(url):
    try:
        response = requests.get(url)
        response.raise_for_status()  # Raise an error for bad responses
        # Parse the HTML to extract the price (this part is specific to each site)
        # For demonstration, let's assume we parse a simple HTML structure
        price = float(response.text.split('Price: $')[1].split('<')[0])
        return price
    except requests.RequestException as e:
        print(f"Error fetching {url}: {e}")
        return None

Step 2: Proxy Rotation with Failure Handling

To maintain a reliable connection, we need to rotate proxies. We'll use a list of proxy URLs and implement failure handling to switch to the next proxy if one fails.

proxies = [
    'http://proxy1.example.com',
    'http://proxy2.example.com'
]

def fetch_price_with_proxy(url):
    for proxy in proxies:
        try:
            response = requests.get(url, proxies={'http': proxy, 'https': proxy})
            response.raise_for_status()
            price = float(response.text.split('Price: $')[1].split('<')[0])
            return price
        except Exception as e:
            print(f"Error with proxy {proxy}: {e}")
    return None  # Return None if all proxies fail

Step 3: Scheduling Requests with APScheduler

We'll use APScheduler to schedule our requests. This allows us to monitor prices at regular intervals.

from apscheduler.schedulers.blocking import BlockingScheduler

def job():
    urls = [
        'https://example.com/product1',
        'https://example.com/product2'
    ]
    for url in urls:
        price = fetch_price_with_proxy(url)
        if price is not None:
            print(f"Price of {url}: ${price}")

scheduler = BlockingScheduler()
scheduler.add_job(job, 'interval', minutes=30)  # Schedule the job to run every 30 minutes

try:
    scheduler.start()
except (KeyboardInterrupt, SystemExit):
    pass

Step 4: Storing Data in SQLite and Sending Alerts

We'll store prices in an SQLite database and send alerts when a price threshold is breached.

import sqlite3
from telegram import Bot

# Initialize SQLite database
conn = sqlite3.connect('prices.db')
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS prices (url TEXT, price REAL)''')
conn.commit()

def store_price(url, price):
    c.execute("INSERT INTO prices VALUES (?, ?)", (url, price))
    conn.commit()

def send_telegram_alert(bot_token, chat_id, message):
    bot = Bot(token=bot_token)
    bot.send_message(chat_id=chat_id, text=message)

# Modify the job function to store prices and check thresholds
def job():
    urls = [
        'https://example.com/product1',
        'https://example.com/product2'
    ]
    for url in urls:
        price = fetch_price_with_proxy(url)
        if price is not None:
            print(f"Price of {url}: ${price}")
            store_price(url, price)
            # Check if the price breaches a threshold
            c.execute("SELECT price FROM prices WHERE url=?", (url,))
            stored_price = c.fetchone()
            if stored_price and price < stored_price[0] * 0.9:  # Example threshold
                send_telegram_alert('YOUR_BOT_TOKEN', 'YOUR_CHAT_ID', f"Price alert for {url}: ${price}")

scheduler.add_job(job, 'interval', minutes=30)

Conclusion

This guide has provided a comprehensive approach to setting up an automated price monitoring system using Python. We covered fetching prices with requests and proxies, scheduling requests with APScheduler, storing data in SQLite, and sending alerts via Telegram.

For professional use cases requiring reliable rotating proxies for production, services like Bright Data and SmartProxy are excellent options. They offer geo-targeted residential proxies that can help you obtain location-accurate prices from various websites.

If you'd rather not manage proxy lists manually, ProxyForge auto-tests and rotates proxies locally on your machine — one-off $29 unlock, no subscription:

https://proxyforge.dev/#download

Free proxies break. ProxyForge doesn't.

The free lists above are public and often unreliable. ProxyForge auto-tests and rotates proxies on your machine, your IP — no stale lists, no shared pools, no surprises. One-off purchase, no subscription.

Download ProxyForge free →