Nov 4, 2024
Online Purchase Bot
One of my girlfriend’s favorite hobbies is buying Hermès bags. She used to browse the Hermès website almost daily but would often end up frustrated because the popular bags sold out so quickly.
To ease her grumbling (and keep the peace), I decided to create an online purchase bot just for her. This app checks the availability of specific bags on the Hermès website every minute. When a new arrival is detected, the bot springs into action—it rings an alarm, sends an email notification, and even completes the purchase automatically, just like a human.
Key features:
-Real-time monitoring: The bot checks the website every minute for new arrivals.
-Notifications: Sends an alarm and email as soon as it detects a restock.
-Automation: Completes the purchase process in under 30 seconds—no human intervention needed!
Here’s a look at the user interface
And here’s an example of the email notification it sends:
This video shows the entire automation process, which can finish the entire purchase with less than 30 seconds from detection!
Creating this app was surprisingly straightforward. Here’s a quick breakdown of the main components:
1. Web Scraping
The first step is learning how to scrape website content. I used Python’s popular libraries, requests
(https://pypi.org/project/requests/) and BeautifulSoup
(https://pypi.org/project/beautifulsoup4/), to retrieve and parse the Hermès website data. Here’s an example of the basic scraping code:
import requests
from bs4 import BeautifulSoup
# Send a GET request to the website
url = "https://www.example.com"
response = requests.get(url)
# Check if the request was successful
if response.status_code == 200:
# Parse the HTML content of the page
soup = BeautifulSoup(response.content, "html.parser")
# Extract the data you want
# Example: Extract all the links on the page
links = soup.find_all("a")
for link in links:
print(link.get("href"))
else:
print("Failed to retrieve the webpage")
2. Mimicking Human Actions
To automate the purchase process, I used the pyautogui
(https://pyautogui.readthedocs.io/en/latest/) library. This library lets you mimic human actions like moving the mouse, clicking buttons, and typing text. For example, to locate and click a “pay” button:
import pyautogui
# Locate an image on screen
image_location = pyautogui.locateOnScreen(image_path)
# Move the mouse to the coordinates (100, 200)
pyautogui.moveTo(100, 200, duration=0.5)
# Click the mouse at the current position
pyautogui.click()
# Type the text "Hello, World!"
pyautogui.typewrite("Hello, World!")
# Press the Enter key
pyautogui.press("enter")
3. Notifications and User Interface
Other than those, you may also need tkinter library (https://docs.python.org/3/library/tkinter.html) for user interface, and email library (https://docs.python.org/3/library/email.examples.html) for sending email.
This project was not just fun but also super practical (for my sanity). If you’re into web scraping, automation, or just want to save someone from the frustration of online shopping, give it a try!
Hope you enjoy this app!
Written by JJ on Nov 4th, 2024
More Details
Good job!