Code: Select all
import requests
from bs4 import BeautifulSoup
import time
# URL of the website to monitor
url = 'https://nbeub.ca/index.php?page=current-petroleum-prices-2'
# Function to fetch the number from the website
def fetch_number():
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
# Adjust the selector to find the specific number
number = soup.select_one('body > table > tbody > tr:nth-child(5) > td > table > tbody > tr > td > table > tbody > tr > td:nth-child(3) > table > tbody > tr:nth-child(3) > td:nth-child(2)')
return str(number)
# Main monitoring function
def monitor():
last_number = fetch_number()
print(f"Initial number: {last_number}")
while True:
time.sleep(2592000) # Wait for 30 days before checking again
current_number = fetch_number()
if current_number != last_number:
print(f"Number updated: {current_number}")
last_number = current_number
# Start monitoring
monitor()