Automation Lab
•
2024-03-06
Discord通知付き最安値追跡ボット
所要時間
12 MIN
必要環境
Python 3.x, Requests, BeautifulSoup
概要
最安値を逃さない
「昨日まで安かったのに...」という後悔をなくしましょう。Pythonを使って、ECサイトの価格を定期的にチェックし、目標価格を下回った瞬間にDiscordへメッセージを飛ばすボットを構築します。
仕組み
- スクレイピング: サイトから現在の価格を取得。
- ロジック: 「目標価格」と比較。
- Webhook: Discordのチャンネルに通知を送信。
01
ステップ 1 実装コード
import requests
from bs4 import BeautifulSoup
URL = "https://www.example-store.com/item-123"
HEADERS = {"User-Agent": "Mozilla/5.0"}
TARGET_PRICE = 5000 # 5000円以下なら通知
def check_price():
res = requests.get(URL, headers=HEADERS)
soup = BeautifulSoup(res.content, 'html.parser')
# IDやクラス名はサイトに合わせて変更してください
price_text = soup.find(id="priceblock_ourprice").get_text()
price = int(price_text.replace('¥', '').replace(',', ''))
if price <= TARGET_PRICE:
send_discord_alert(price)
def send_discord_alert(price):
webhook_url = "あなたのDISCORD_WEBHOOK_URL"
data = {"content": f"🚨 値下げ通知! 現在 {price}円です!急いで!\n{URL}"}
requests.post(webhook_url, json=data)
check_price()
運用
サーバーレス運用
GitHub Actions を使えば、このプログラムを24時間、1時間おきに無料で実行し続けることができます。サーバー代は0円です。