Test Code

import requests
import time
from bs4 import BeautifulSoup

# URL of the webpage to monitor
url = 'https://www.buffalotracedistillery.com/product-availability'

# Set the initial availability status
availability = ''

while True:
    # Send a GET request to the URL and get the HTML content
    response = requests.get(url)
    html = response.content
    # Parse the HTML content with BeautifulSoup
    soup = BeautifulSoup(html, 'html.parser')
    # Find the availability status by looking for the h4 tag with class "product-is-available" or "product-is-not-available"
    available_tag = soup.find('h4', {'class': 'product-is-available'})
    not_available_tag = soup.find('h4', {'class': 'product-is-not-available'})
    # Check if the availability status has changed
    if available_tag is not None:
        new_availability = 'In Stock'
    elif not_available_tag is not None:
        new_availability = 'Sold Out'
        new_availability = 'Unknown'
    if new_availability != availability:
        # Notify the user that the availability status has changed
        print('The availability status has changed to:', new_availability)
        # Update the availability status
        availability = new_availability
    # Add a delay of 300 seconds before sending the next request

Create a free website or blog at WordPress.com.

Up ↑