如何用appium使用手机淘宝秒杀优惠券?

 # 点击搜索框
    driver.execute_script('mobile: shell', {
        'command': 'input',
        'args': ['tap', 490, 334]
    })
    print('点击成功')
    time.sleep(2)

    # 输入口令
    driver.execute_script('mobile: type', {'action': 'replaceText', 'text': '88🗝Y8evdrURwrH💲 https://m.tb.cn/h.UB4kA32  CZ0001 有价券'}) # 填写淘口令

    # 计算抢购时间和刷新时间
    target_time = datetime.datetime.now().replace(hour=20, minute=0, second=0, microsecond=0)

    current_time = datetime.datetime.now()
    time_diff = (target_time - current_time).total_seconds() - 1.8
    if time_diff > 0:
        time.sleep(time_diff)

    # 记录开始进入时间
    start_refresh_time = datetime.datetime.now()

    # 点击搜索
    driver.execute_script('mobile: shell', {
        'command': 'input',
        'args': ['tap', 1100, 187]
    })
    print('成功跳转')
    time.sleep(1)

    # 记录结束刷新时间
    end_refresh_time = datetime.datetime.now()
    print(f'当前时间:{end_refresh_time}')

    try:
        time.sleep(1)
        # 勾选授权协议
        driver.execute_script('mobile: shell', {
            'command': 'input',
            'args': ['tap', 94, 1170]
        })
        print('勾选成功')
    except Exception as e:
        print('勾选失败', e)

    while True:
        x = 618
        y = 1007
        try:
            click_count = 50
            for i in range(click_count):
                driver.execute_script('mobile: shell', {
                    'command': 'input',
                    'args': ['tap', str(x), str(y)]
                })
                print(f'第{i+1}次点击')
            # 等待元素出现
            try:
                if driver.execute_script('mobile: shell', {
                    'command': 'input',
                    'args': ['tap', 618, 2411]
                }):
                    print("抢购成功")
                    speaker.Speak("订单提交成功,我已帮你抢到优惠券啦,请及时支付订单")
                    break
                else:
                    print('抢购失败')
                    for i in range(click_count):
                        driver.execute_script('mobile: shell', {
                            'command': 'input',
                            'args': ['tap', str(x), str(y)]
                        })
            except Exception as e:
                print("未找到元素", e)

            # 记录抢购成功时间
            success_time = datetime.datetime.now()

            # 获取当前时间精确到毫秒
            current_time = success_time.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
            print("当前时间:", current_time)

            refresh_process_time = (end_refresh_time - start_refresh_time).total_seconds()
            print('过程时间:', refresh_process_time, '秒')

        except Exception as e:
            print('点击失败', e)

    print('抢购结束')

这是我抢购代码中的重要部分,首先我通过在搜索框中输入口令。然后在优惠券时间开始前1.8秒钟就开始跳转页面,然后开始勾选协议,按抢购按钮,我还怕按一次不行,就设置了快速按50次。但是为什么每次都在优惠券开始的一秒钟时间全部就秒杀完了,请问,这是什么原因导致的。

首先,我们需要明确一点,手机淘宝的优惠券秒杀是一个非常高并发、高负载的操作,每秒钟会有大量用户在进行抢购。由于抢购时间非常短暂,大量用户同时在操作,所以这个问题可能是因为您的代码执行速度比其他用户的抢购速度慢,导致未能成功抢到优惠券。

除此之外,还有一些其他原因可能会导致您的抢购不成功:

您的代码中没有考虑到网络延迟等因素,导致网速过慢或者请求超时,从而导致抢购失败。
您的代码中没有设置合适的请求频率,导致请求过于频繁或者过于慢,从而导致服务器对您的请求做出限制或者忽略。
您的代码中没有考虑到优惠券数量有限,可能已经被其他用户抢光了。
建议您可以使用appium提供的等待机制,设置好适当的等待时间,从而在请求时避免网络延迟等问题。同时您可以调整请求频率,避免请求过于频繁或过于慢。
最后,也可以尝试在优惠券抢购开始前几毫秒就开始请求,现在很多秒杀软件都是可以设置提前点击的,从而增加抢购成功的概率。

可能是因为你的抢购脚本和其他人的抢购脚本同时在进行,导致竞争激烈,因此在瞬间秒杀完了。另外,可能是因为你的抢购脚本没有考虑到网络延迟等因素,导致执行速度不够快。建议你可以尝试优化你的抢购脚本,例如增加重试机制、减少请求间隔等方式来提高抢购成功率。

按键模拟是最低级的,JavaScript脚本也不行,学post编程吧

最后,你学会post编程还会发现有很长一段路要走。抓包,多线程,多账号,豪秒级,流量限制