**Web Monitoring Bot Python Free: Build Your Own Price Tracker in Minutes**
π TYPE: Free Tool / Script
π° COST: 100% FREE
⏱️ SETUP TIME: Under 5 minutes
---
Stuck watching a product’s price drop or a website change, only to miss it? You’re not alone. Developers, students, and tech enthusiasts often juggle multiple sites, product launches, and price alerts. A free, lightweight Python bot automates the task, delivering real‑time updates via email or push notifications. With minimal setup, you can stay in the loop, save money, and free up time for the things that matter.
Manual monitoring wastes hours and risks missing critical moments. By automating the process, you:
- Save time – run overnight checks instead of staring at the screen.
- Increase accuracy – no more human slip‑ups; the bot follows a strict routine.
- Improve responsiveness – get instant alerts that can spark quick purchases or content updates.
- Scale easily – monitor dozens of URLs without additional effort.
1. Set up your environment
- Install Python 3.10+ from python.org.
- Create a virtual environment: `python -m venv webmon`.
- Activate it: `webmon\Scripts\activate` (Windows) or `source webmon/bin/activate` (Linux/macOS).
2. Install dependencies
`requests` fetches pages, `beautifulsoup4` parses HTML, and `schedule` runs periodic jobs.
3. Identify what to monitor
- Pick the target URL.
- Use the browser’s Inspect tool to locate the element containing the price or text. Note its CSS selector or XPath.
4. Create a config file (config.json)
This JSON lets you add multiple sites, adjust intervals, and choose alert methods.
5. Write the monitoring script (see *THE CODE* below).
- Load `config.json`.
- For each target, fetch the page and parse the desired element.
- Store the previous value; if it changes, trigger an alert.
- Use `schedule.every().minutes.do(...)` to set the polling frequency.
6. Run and test
- Execute `python monitor.py`.
- Verify the console prints a new line when the monitored data changes.
- Pause the script, manually edit the webpage (or the test page), then resume to see the bot catch the alteration.
7. Automate execution
- On Windows, create a scheduled task that runs the script daily.
- On Linux, add a cron job: `0 * * * * /path/to/webmon/bin/python /path/to/monitor.py`.
- Add new sites: Append objects to the `"targets"` array in `config.json`.
- Change selectors: Replace the `"css"` or `"xpath"` strings with the correct path.
- Adjust intervals: Alter `"check_interval"` per site (in seconds).
- Extend notifications: In the `alert()` function, plug in an SMTP block or Twilio API for email/SMS alerts.
- Missing element: Ensure selector matches the page after any JavaScript load; you might need Selenium for dynamic content.
- Request blocks: Sites may block rapid requests; add headers like `User-Agent`.
- Cron not running: Verify the environment path and that the script is executable.
You now have a zero‑cost, Python‑powered web monitoring bot that keeps you posted on the changes that matter. Next, try integrating a database to log every change, or swap the console alert for a Discord webhook to share updates with a community. Happy automating!
TAGS: python, automation, bots, free‑tools, scripts
INTRO
Stuck watching a product’s price drop or a website change, only to miss it? You’re not alone. Developers, students, and tech enthusiasts often juggle multiple sites, product launches, and price alerts. A free, lightweight Python bot automates the task, delivering real‑time updates via email or push notifications. With minimal setup, you can stay in the loop, save money, and free up time for the things that matter.
WHY YOU NEED THIS
Manual monitoring wastes hours and risks missing critical moments. By automating the process, you:
- Save time – run overnight checks instead of staring at the screen.
- Increase accuracy – no more human slip‑ups; the bot follows a strict routine.
- Improve responsiveness – get instant alerts that can spark quick purchases or content updates.
- Scale easily – monitor dozens of URLs without additional effort.
STEP BY STEP GUIDE
1. Set up your environment
- Install Python 3.10+ from python.org.
- Create a virtual environment: `python -m venv webmon`.
- Activate it: `webmon\Scripts\activate` (Windows) or `source webmon/bin/activate` (Linux/macOS).
2. Install dependencies
pip install requests beautifulsoup4 schedule
`requests` fetches pages, `beautifulsoup4` parses HTML, and `schedule` runs periodic jobs.
3. Identify what to monitor
- Pick the target URL.
- Use the browser’s Inspect tool to locate the element containing the price or text. Note its CSS selector or XPath.
4. Create a config file (config.json)
{
"targets":[
{
"url":"https://example.com/product",
"selector":{"css":"span.price"},
"check_interval":300
}
],
"alert":{"type":"console"}
}
"targets":[
{
"url":"https://example.com/product",
"selector":{"css":"span.price"},
"check_interval":300
}
],
"alert":{"type":"console"}
}
This JSON lets you add multiple sites, adjust intervals, and choose alert methods.
5. Write the monitoring script (see *THE CODE* below).
- Load `config.json`.
- For each target, fetch the page and parse the desired element.
- Store the previous value; if it changes, trigger an alert.
- Use `schedule.every().minutes.do(...)` to set the polling frequency.
6. Run and test
- Execute `python monitor.py`.
- Verify the console prints a new line when the monitored data changes.
- Pause the script, manually edit the webpage (or the test page), then resume to see the bot catch the alteration.
7. Automate execution
- On Windows, create a scheduled task that runs the script daily.
- On Linux, add a cron job: `0 * * * * /path/to/webmon/bin/python /path/to/monitor.py`.
THE CODE
import json
import time
import requests
from bs4 import BeautifulSoup
import schedule
with open("config.json") as f:
cfg = json.load(f)
prev_values = {}
def check_target(target):
url = target["url"]
selector = target["selector"]
try:
resp = requests.get(url, timeout=10)
resp.raise_for_status()
except requests.RequestException as e:
print(f"[ERROR] Failed to fetch {url}: {e}")
return
soup = BeautifulSoup(resp.text, "html.parser")
if "css" in selector:
elem = soup.select_one(selector["css"])
else:
elem = soup.select_one(selector["xpath"])
if not elem:
print(f"[WARN] Element not found for {url}")
return
current_text = elem.get_text(strip=True)
prev = prev_values.get(url)
if prev is None:
prev_values[url] = current_text
elif prev != current_text:
alert(url, current_text, prev)
prev_values[url] = current_text
def alert(url, current, previous):
msg = f"π {url}\nChanged from '{previous}' to '{current}'"
if cfg["alert"]["type"] == "console":
print(msg)
# Expand with email or SMS by adding more alert types here
for target in cfg["targets"]:
schedule.every(target["check_interval"]).seconds.do(check_target, target)
while True:
schedule.run_pending()
time.sleep(1)
import time
import requests
from bs4 import BeautifulSoup
import schedule
Load configuration
with open("config.json") as f:
cfg = json.load(f)
prev_values = {}
def check_target(target):
url = target["url"]
selector = target["selector"]
try:
resp = requests.get(url, timeout=10)
resp.raise_for_status()
except requests.RequestException as e:
print(f"[ERROR] Failed to fetch {url}: {e}")
return
soup = BeautifulSoup(resp.text, "html.parser")
if "css" in selector:
elem = soup.select_one(selector["css"])
else:
elem = soup.select_one(selector["xpath"])
if not elem:
print(f"[WARN] Element not found for {url}")
return
current_text = elem.get_text(strip=True)
prev = prev_values.get(url)
if prev is None:
prev_values[url] = current_text
elif prev != current_text:
alert(url, current_text, prev)
prev_values[url] = current_text
def alert(url, current, previous):
msg = f"π {url}\nChanged from '{previous}' to '{current}'"
if cfg["alert"]["type"] == "console":
print(msg)
# Expand with email or SMS by adding more alert types here
Schedule all targets
for target in cfg["targets"]:
schedule.every(target["check_interval"]).seconds.do(check_target, target)
while True:
schedule.run_pending()
time.sleep(1)
HOW TO CUSTOMIZE
- Add new sites: Append objects to the `"targets"` array in `config.json`.
- Change selectors: Replace the `"css"` or `"xpath"` strings with the correct path.
- Adjust intervals: Alter `"check_interval"` per site (in seconds).
- Extend notifications: In the `alert()` function, plug in an SMTP block or Twilio API for email/SMS alerts.
COMMON ISSUES
- Missing element: Ensure selector matches the page after any JavaScript load; you might need Selenium for dynamic content.
- Request blocks: Sites may block rapid requests; add headers like `User-Agent`.
- Cron not running: Verify the environment path and that the script is executable.
CONCLUSION
You now have a zero‑cost, Python‑powered web monitoring bot that keeps you posted on the changes that matter. Next, try integrating a database to log every change, or swap the console alert for a Discord webhook to share updates with a community. Happy automating!
TAGS: python, automation, bots, free‑tools, scripts
π Want more? I have a Sheets Templates Bundle with 50+ ready-to-use scripts starting at $17.
But this free one above? It's genuinely complete on its own. No catch.
Comments
Post a Comment