分享CSTserver 9.9活动鸡监控抢购脚本,青龙面板监控,自动抢VPS的脚本

在NS看到一个抢VPS的脚本,分享CSTserver 9.9活动鸡监控抢购脚本,前几天用AI辅助写了一套CSTserver 9.9活动鸡的监控+抢购py脚本,失败几次后成功抢到一台。不仅仅可用于抢CSTSERVER  CSTserver:香港/圣何塞/洛杉矶机房,上云仅需$9.9/年  也可以抢其它的,需要变动的可以自行修改 不懂的也可以问AI

图片[1]-CSTserver:香港/圣何塞/洛杉矶机房,上云仅需$9.9/年,裸金属$17.99/月,独服$39.99/月-VPS SO

使用方法

  1. 找个服务器部署青龙面板(推荐宝塔/1panel等应用商店直接docker安装)
  2. 青龙安装selenium模块,可参考这个步骤:https://github.com/jzjbyq/AutoCheckIn
  3. 青龙面板-脚本管理,创建脚本文件cst_monitor.py,粘贴下述脚本代码,修改MY_USERNAME和MY_PASSWORD为自己的账号密码
  4. 青龙面板-定时任务,创建任务,任务名称随意,脚本填写cst_monitor.py,定时规则填写 0 */5 * * * * 即可(每5分钟重新执行一次)
  5. 启用任务,检查是否正确输出监控日志
  6. 抢购成功后可以在官网控制台看到待支付的订单,需要手动支付

注意事项

  1. 脚本基于selenium模拟浏览器操作而非post请求,延迟较高,无法保证成功! 如果提示操作错误大概率就是抢慢了
  2. 推荐先用其他产品的url测试一遍下单流程是否正常,测试无误后再改回活动型号的链接
  3. 暂不清楚如何修改抢购时的配置项,默认配置下开的应该都是38段的机器
  4. 目前机器使用感受普通且服务商持续放货,不建议溢价收鸡囤货炒鸡

脚本代码

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import datetime as dt
import time

MY_USERNAME = "abc@abc.com"  # 替换为实际的邮箱地址
MY_PASSWORD = "123456"  # 替换为实际的登录密码
MY_PROMOTION_CODE = "CSTOU4"  # 替换为实际的promotion code
AUTO_BUY = True # 是否开启抢购
CHECK_INTERVAL = 15 # 页面检测间隔,默认15秒
MAX_TIME = 300 # 脚本最大执行时长,默认300秒(5分钟)

# selenium浏览器配置
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=chrome_options)

# 跳转到产品页面
product_url = 'https://cstserver.com/index.php?rp=/store/hong-kong-cloud-serverlimit-flow/cvm-amd-epyc-c1&mode=console'
#product_url = 'https://cstserver.com/cart.php?a=add&pid=223&mode=console' # 测试用
driver.get(product_url)

# 最多刷新检测MAX_TIME//CHECK_INTERVAL次
n = MAX_TIME // CHECK_INTERVAL
for i in range(n):
    # 等待页面加载完成
    wait = WebDriverWait(driver, 20)

    # 检查页面中是否有"out of stock"字样
    out_of_stock_text = "out of stock"
    if out_of_stock_text in driver.page_source.lower():
        print(f"发现页面中有'{out_of_stock_text}'字样,提示缺货。")
        #t = dt.datetime.strftime(dt.datetime.now(), '%Y-%m-%d %H:%M:%S')
        #QLAPI.notify('青龙 - CST抢购', f'{t}\n检测到库存缺货!')

        # 刷新浏览器页面
        print(f"开始第{i+1}次刷新库存检测...")
        time.sleep(CHECK_INTERVAL) # 等待CHECK_INTERVAL秒后再次执行
        driver.refresh()
    else:
        print("未发现缺货提示。")
        t = dt.datetime.strftime(dt.datetime.now(), '%Y-%m-%d %H:%M:%S')
        QLAPI.notify('青龙 - CST抢购', f'{t}\n检测到库存已补货!')

        # 开始抢购
        if AUTO_BUY:
            try:
                # 显式等待直到按钮可点击
                buy_button = wait.until(EC.element_to_be_clickable((By.ID, 'btnCompleteProductConfig')))
                # 使用JavaScript点击
                driver.execute_script("arguments[0].click();", buy_button)
                print("成功通过JavaScript点击购买按钮。")

                # 等待新页面加载
                wait.until(EC.presence_of_element_located((By.ID, 'inputPromotionCode')))

                # 找到promotion code输入框
                promotion_code_input = driver.find_element(By.ID, 'inputPromotionCode')
                # 输入promotion code
                promotion_code_input.send_keys(MY_PROMOTION_CODE)
                print(f"成功输入promotion code: {MY_PROMOTION_CODE}")

                # 找到validate code按钮
                validate_code_button = wait.until(EC.element_to_be_clickable((By.NAME, 'validatepromo')))
                # 使用JavaScript点击validate code按钮
                driver.execute_script("arguments[0].click();", validate_code_button)
                print("成功通过JavaScript点击validate code按钮。")

                # 找到checkout按钮
                checkout_button = wait.until(EC.element_to_be_clickable((By.ID, 'checkout')))
                # 使用JavaScript点击checkout按钮
                driver.execute_script("arguments[0].click();", checkout_button)
                print("成功通过JavaScript点击checkout按钮。")

                # 找到并点击已注册按钮
                already_registered_button = wait.until(EC.element_to_be_clickable((By.ID, 'btnAlreadyRegistered')))
                driver.execute_script("arguments[0].click();", already_registered_button)
                print("成功点击已注册按钮。")

                # 等待登录表单元素加载
                login_email_input = wait.until(EC.visibility_of_element_located((By.ID, 'inputLoginEmail')))
                login_password_input = wait.until(EC.visibility_of_element_located((By.ID, 'inputLoginPassword')))

                # 输入邮箱地址和登录密码
                login_email_input.send_keys(MY_USERNAME)
                login_password_input.send_keys(MY_PASSWORD)
                print(f"成功输入邮箱地址和登录密码。")

                # 勾选同意协议的复选框
                agree_checkbox = wait.until(EC.element_to_be_clickable((By.ID, 'iCheck-accepttos')))
                driver.execute_script("arguments[0].click();", agree_checkbox)
                print("成功勾选同意协议的复选框。")

                # 找到并点击完成订单按钮
                #complete_order_button = wait.until(EC.element_to_be_clickable((By.ID, 'btnCompleteOrder')))
                #driver.execute_script("arguments[0].click();", complete_order_button)
                print("成功点击完成订单按钮。")
                t = dt.datetime.strftime(dt.datetime.now(), '%Y-%m-%d %H:%M:%S')
                QLAPI.notify('青龙 - CST抢购', f'{t}\n订单创建成功!')
            except Exception as e:
                print(f"操作过程中发生错误: {e}")
                t = dt.datetime.strftime(dt.datetime.now(), '%Y-%m-%d %H:%M:%S')
                QLAPI.notify('青龙 - CST抢购', f'{t}\n抢购操作错误!')
# 关闭浏览器
driver.quit()

 

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享