脚本

import time
import datetime

from playwright.sync_api import sync_playwright
import pytest
from selenium.common import NoSuchElementException, ElementNotInteractableException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

def pay():
    # playwrightUI自动化工具
    with sync_playwright() as playwright:
        context = playwright.chromium.launch_persistent_context(
            user_data_dir="../",
            headless=False,
            slow_mo=500,
            viewport={'width': 1920, 'height': 1080}
        )

        page = context.new_page()

        # 设置商品地址
        page.goto("https://www.vmall.com/product/10086429395667.html")
        # page.goto("https://www.vmall.com/product/10086847911493.html")

        # #点击登录
        # if page.locator("#up_loginName").is_hidden():
        #     page.click("#top-index-loginUrl")
        #
        # # 检测是否跳到商品页,等待2分钟,超过就超时,手动登录操作需要时间
        # page.wait_for_selector(selector="#pro-name",timeout=3*60*1000)

        tomorrow = datetime.datetime.combine(datetime.datetime.today(), datetime.time(hour=8, minute=8, second=0))
        print("抢购日期:"+tomorrow.strftime("%Y-%m-%d %H:%M:%S.%f"))
        while tomorrow.timestamp() >= datetime.datetime.now().timestamp():
            localtime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
            print(localtime)
            time.sleep(0.01)

        # 点击下单
        try:
            print('尝试下单')
            start_time = time.time()
            x = page.get_by_text("立即下单").first.click()
        except:
            print(f'下单失败, 再次尝试, used time: {time.time() - start_time}')
            time.sleep(0.5)

        try:
            # 点击确认下单
            time.sleep(0.1)
            page.mouse.wheel(0, 7000)
            page.locator('[seed="checkout-submit"]').click()
            print('提交订单成功')
        except:
            print('下单成功,手动提交订单吧!')
        time.sleep(9000)



if __name__ == "__main__":
    pay()

posted @ 2023-10-28 08:13  疯狂列表推导式  阅读(9)  评论(0编辑  收藏  举报