华为商城抢购mate 60手机的自动化python代码2024.1.8

2024-01-10 13:57:19 浏览数 (2)

1、打开浏览器

2、手动登陆

3、在时间范围内反复寻找,"立即下单""提交订单"按钮,一旦出现就按

4、手动支付

代码语言:javascript复制
import datetime
from selenium import webdriver
from selenium.webdriver.common.by import By

# 启动Chrome浏览器
driver = webdriver.Chrome()
# 打开华为商城
url = "https://www.vmall.com/index.html"
driver.get(url)
driver.maximize_window()  # 窗口最大化

# 人工登录华为商城
# ...

# 打开要购买商品的页面
product_url = "https://www.vmall.com/product/10086970184614.html"  # Mate60产品ID
driver.get(product_url)

# # 设置抢购时间
start_time_str = "2024-1-8 16:07:50"
start_time = datetime.datetime.strptime(start_time_str, "%Y-%m-%d %H:%M:%S")
end_time = start_time   datetime.timedelta(seconds=180)  # 抢购截止时间设置为3分钟后

# 开始抢购
while True:
    now = datetime.datetime.now()
    if now >= start_time:
        while True:
            print('重试1')
            try:
                driver.find_element(By.LINK_TEXT, "立即下单").click()
                # driver.find_element(By.LINK_TEXT, "即将开始").click()
                print('点击到-立即下单')
                break
            except:
                now = datetime.datetime.now()
                if now > end_time:
                    print('卡在立即下单')
                    break
                else:
                    pass
        
        while True:
            print('重试2')
            try:
                driver.find_element(By.LINK_TEXT, "提交订单").click()
                # print("抢到啦!!!快去支付")
                # driver.find_element(By.LINK_TEXT, "即将开始").click()
                print('点击到-提交订单')
                break
            except:
                now = datetime.datetime.now()
                if now > end_time:
                    print('卡在支付')
                    break
                else:
                    pass
        break

# 支付操作需要人工完成

参考:

https://zhuanlan.zhihu.com/p/663498713

https://www.bilibili.com/video/BV1D34y1P7vw

0 人点赞