仅供学习参考
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) # 间隔秒数