Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3658362
  • 博文数量: 365
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2522
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

全部博文(365)

文章存档

2023年(8)

2022年(130)

2021年(155)

2020年(50)

2019年(22)

我的朋友

分类: Python/Ruby

2022-09-06 11:47:39

# !/usr/bin/env python

# -*- coding: utf-8 -*-

# 2022/09/03

from selenium import webdriver

import datetime

import time

class Seckill():

    def __init__(self,startTime, choose):

        self.startTime = startTime

        self.choose = choose

    def login(self,browser):

        browser.get("")

        time.sleep(2)

        if browser.find_element_by_link_text("亲,请登录"):

            browser.find_element_by_link_text("亲,请登录").click()

            print("请在15秒内完成扫码")

            time.sleep(15)

            browser.get("")

        time.sleep(3)

        now = datetime.datetime.now()

        print('登陆成功:', now.strftime('%Y-%m-%d %H:%M:%S'))

    def buy(self,browser):

        if self.choose == 2:

            print("请手动在浏览器中勾选需要秒杀的商品")

        while True:

            now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')

            # 对比时间,时间到的话就点击结算

            if now > self.startTime:

                if self.choose == 1:

                    while True:

                        try:

                            if browser.find_element_by_id("J_SelectAll2"):

                                browser.find_element_by_id("J_SelectAll2").click()

                                break

                        except:

                            print("error : cant find buy button")

                # 点击结算按钮

                while True:

                    try:

                        if browser.find_element_by_link_text("结 算"):

                            browser.find_element_by_link_text("结 算").click()

                            print("结算成功")

                            break

                    except:

                        pass

                while True:

                    try:

                        if browser.find_element_by_link_text('提交订单'):

                            browser.find_element_by_link_text('提交订单').click()

                            now1 = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')

                            print("抢购成功时间:%s" % now1)

                    except:

                        print("再次尝试提交订单")

                time.sleep(0.01)

def main():

    pkTime = input("请输入秒杀时间,格式如(2022-09-03 15:40:00.000000):")

    choose = int(input("到时间自动勾选购物车请输入“1”,否则输入“2”:"))

    browser =跟单网gendan5.com webdriver.Chrome()

    browser.maximize_window()

    sk = Seckill(pkTime, choose)

    # step1: 登陆

    sk.login(browser)

    # step2: 购买

    sk.buy(browser)

if __name__ == "__main__":

    main()

阅读(466) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~