ClawCloud黑五 JP $4 库存监控

仅供学习参考
1 添加购物车
2 找购物车的cookie填入代码
3 run


代码如下:

import requests
import time

URL = "https://claw.cloud/cart.php?a=checkout"
HEADERS = {
    "accept": "*/*",
    "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
    "cache-control": "no-cache",
    "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
    # 需要先手动加入购物车,应用好折扣代码 #
    "cookie": "_ga=xxxxxxxxxxxxx; g_state={\"i_l\":0}; WHMCSQ9NehDSSeIro=xxxxxxxxxxxxxxxxx",
    # cookie只需抓取【_ga】和【WHMCSQ9NehDSSeIro】 #
    "origin": "https://claw.cloud",
    "referer": "https://claw.cloud/cart.php?a=checkout",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36",
}

# 定义请求数据
PAYLOAD = {
    "selectProductPeriod": 1,
    "pi": 0,
    "pc": "annually"
}


def send_notification():
    try:
        # 推送通知的URL
        PUSH_URL = "http://push.ijingniu.cn/send"
        # 推送通知的参数
        PUSH_PARAMS = {
            "key": "xxxxxxxxx",  # http://push.ijingniu.cn/ 的密钥
            "head": "有库存了",
            "body": "快去抢"
        }
        # 发送推送请求
        response = requests.get(PUSH_URL, params=PUSH_PARAMS)
        response.raise_for_status()  # 检查请求是否成功
        print(f"✅ 已发送通知:{response.json()}")
    except Exception as e:
        print(f"❌ 通知发送失败:{e}")


# 定义检查商品库存和价格的函数
def check_product_discount():
    try:
        # 发起POST请求
        response = requests.post(URL, headers=HEADERS, data=PAYLOAD)
        response.raise_for_status()  # 检查HTTP状态码

        # 解析JSON响应
        data = response.json()

        # 获取总价格字段
        total_price = data.get("total", "$0.00 USD").strip()

        # 如果总价格不等于 "$120.00 USD",说明有折扣
        if total_price != "$120.00 USD":
            print(f"🎉 商品价格变化!当前总价:{total_price}")
            # 发送通知
            send_notification()
        else:
            print("💤 未发现折扣,总价仍为 $120.00 USD")
    except Exception as e:
        print(f"❌ 请求出错:{e}")


# 定义一个定时监控的主函数
def monitor_product(interval=60):
    print("开始监控商品是否有折扣...")
    while True:
        check_product_discount()
        time.sleep(interval)


# 程序入口
if __name__ == "__main__":
    monitor_product(interval=60)  # 间隔秒数

9 Likes

想念HK4刀

如果再给我一次机会 :smiling_face_with_tear:

点个赞…感谢分享

JP的有用吗,HK的还差不多。

4刀还是年付啊

不管是4刀还是年付 有库存就提醒

代码更新

from datetime import datetime

import requests
import time

URL = "https://claw.cloud/cart.php?a=checkout"
HEADERS = {
    "accept": "*/*",
    "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
    "cache-control": "no-cache",
    "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
    # 需要先手动加入购物车,应用好折扣代码 #
    "cookie": "_ga=GAxxxxxxxx; g_state={\"i_l\":0}; WHMCSQ9NehDSSeIro=xxxxx",
    # cookie只需抓取【_ga】和【WHMCSQ9NehDSSeIro】 #
    "origin": "https://claw.cloud",
    "referer": "https://claw.cloud/cart.php?a=checkout",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36",
}

# 定义请求数据
PAYLOAD = {
    "selectProductPeriod": 1,
    "pi": 0,
    "pc": "annually"
}


def send_notification(msg):
    try:
        # 推送通知的URL
        PUSH_URL = "http://push.ijingniu.cn/send"
        # 推送通知的参数
        PUSH_PARAMS = {
            "key": "xxxxxxxxxxxxxx",  # http://push.ijingniu.cn/ 的密钥
            "head": msg,
            "body": msg
        }
        # 发送推送请求
        response = requests.get(PUSH_URL, params=PUSH_PARAMS)
        response.raise_for_status()  # 检查请求是否成功
        print(f"✅ 已发送通知:{response.json()}")
    except Exception as e:
        print(f"❌ 通知发送失败:{e}")


# 定义检查商品库存和价格的函数
def check_product_discount():
    try:
        # 发起POST请求
        response = requests.post(URL, headers=HEADERS, data=PAYLOAD)
        response.raise_for_status()  # 检查HTTP状态码

        # 解析JSON响应
        data = response.json()

        # 获取总价格字段
        total_price = data.get("total", "$0.00 USD").strip()

        if total_price == "$0.00 USD":
            msg = f"{datetime.now()}❌ cookie过期"
            print(msg)
            send_notification(msg)
            exit()
        elif total_price != "$120.00 USD":
            msg = f"{datetime.now()}✅ 获取到折扣,总价为 {total_price}"
            print(msg)
            # 发送通知
            send_notification(msg)
        else:
            print(f"{datetime.now()}💤 未发现折扣,总价仍为 $120.00 USD")
    except Exception as e:
        msg = f"{datetime.now()}❌ 请求出错:{e}"
        print(msg)
        send_notification(msg)
        exit()


# 定义一个定时监控的主函数
def monitor_product(interval=60):
    print("开始监控商品是否有折扣...")
    while True:
        check_product_discount()
        time.sleep(interval)


# 程序入口
if __name__ == "__main__":
    monitor_product(interval=30)  # 间隔秒数