Python版中秋佳節月餅搶購指令碼

專注的阿熊發表於2022-09-06

# !/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 =外匯跟單gendan5.com 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 = webdriver.Chrome()

     browser.maximize_window()

     sk = Seckill(pkTime, choose)

     # step1: 登陸

     sk.login(browser)

     # step2: 購買

     sk.buy(browser)

if __name__ == "__main__":

     main()


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69946337/viewspace-2913584/,如需轉載,請註明出處,否則將追究法律責任。

相關文章