Taobao refreshes the shopping cart and submits the order in about 5 seconds

import them
from selenium import webdriver
import datetime
import time


#Need to download deckodreiver
firefox = os.path.abspath(r"D:\Program Files\Mozilla Firefox\firefox.exe")
os.environ["webdriver.firefox.bin"] = firefox
driver = webdriver.Firefox()
driver.maximize_window()

def login(uname, pwd):
  driver.get("https://www.taobao.com")
  if driver.find_element_by_link_text("Dear, please log in"):
    driver.find_element_by_link_text("Dear, please log in").click()
  input(uname, pwd)

  #Click the select all button in the shopping cart
  if driver.find_element_by_id("J_SelectAll1"):
    driver.find_element_by_id("J_SelectAll1").click()
  # time.sleep(3)
  now = datetime.datetime.now()
  print('login success:', now.strftime('%Y-%m-%d %H:%M:%S'))

  

def input(uname,pwd):
  time.sleep(3)
  #Select password to log in
  if driver.find_element_by_id("J_Quick2Static"):
    driver.find_element_by_id("J_Quick2Static").click()
  time.sleep(3)

  #Username input
  if driver.find_element_by_name("TPL_username"):
    for i in uname:
      driver.find_element_by_name("TPL_username").send_keys(i)
      time.sleep(0.5)
  time.sleep(3)

  #password input
  if driver.find_element_by_name("TPL_password"):
    for j in pwd:
      driver.find_element_by_name("TPL_password").send_keys(j)
      time.sleep(0.5)
  time.sleep(3)

  #Click the login button
  if driver.find_element_by_id("J_SubmitStatic"):
    driver.find_element_by_id("J_SubmitStatic").click()
  time.sleep(3)
  driver.get("https://cart.taobao.com/cart.htm")
  time.sleep(2)

def buy(buytime):
  while True:
    now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    if now == buytime:
      driver.find_element_by_id("mc-menu-hd").click() #Click on the shopping cart
      time.sleep(0.5)
      driver.find_element_by_id("J_SelectAll1").click() #Click to select all
      time.sleep(0.2)
      
      try:
        if driver.find_element_by_id("J_Go"): #Click the settlement button
            driver.find_element_by_id("J_Go").click()
            print("Found!!!! Settlement")
        else:
            print("No settlement found")
        time.sleep(1)  
        driver.find_element_by_link_text('Submit order').click()
        print("Found!!!! Submit order")
      except:
        time.sleep(1)
        
          
    print(now)
    time.sleep(1)
if __name__=="__main__":
  #Chinese account remember to decode the code
  login("account",'password')
  buy('2018-03-28 15:48:59') #Refresh one second in advance

Can anyone help improve the speed of placing orders? 5 seconds is too long

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326068903&siteId=291194637