Python to achieve taobao seconds kill sample code

  • 2020-06-23 00:51:02
  • OfStack

The novice learned Python. Before, I saw 40 lines of Python code written by a friend on the Internet and wanted to grab a doll for my girlfriend on Taobao. Therefore, I wrote the script of Python on Taobao. Direct code:


#-*- coding: UTF-8 -*-
import os
from selenium import webdriver
import datetime
import time
chromedriver = "/usr/bin/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
def login(uname, pwd):
  driver.get("https://www.taobao.com")
  if driver.find_element_by_link_text(" Please log in, dear "):
    driver.find_element_by_link_text(" Please log in, dear ").click();
  time.sleep(1)
  if driver.find_element_by_link_text(" Password to login "):
    driver.find_element_by_link_text(" Password to login ").click();
  time.sleep(1)
  if driver.find_element_by_name("TPL_username"):
    driver.find_element_by_name("TPL_username").send_keys(uname);
  time.sleep(1)
  if driver.find_element_by_name("TPL_password"):
    driver.find_element_by_name("TPL_password").send_keys(pwd);
  time.sleep(2)
  if driver.find_element_by_id("J_SubmitStatic"):
    driver.find_element_by_id("J_SubmitStatic").click();
  time.sleep(1)
  driver.get("https://cart.taobao.com/cart.htm")
  if driver.find_element_by_id("J_SelectAll1"):
    driver.find_element_by_id("J_SelectAll1").click()
  time.sleep(3)
  if driver.find_element_by_link_text(" "   calculate "):
    driver.find_element_by_link_text(" "   calculate ").click();
  now = datetime.datetime.now()
  print('login success:', now.strftime('%Y-%m-%d %H:%M:%S'))
def buy_on_time(buytime):
  while True:
    now = datetime.datetime.now()
    if now.strftime('%Y-%m-%d %H:%M:%S') == buytime:
      while True:
        try:
          driver.find_element_by_link_text(' Submit orders ').click()
        except:
          time.sleep(1)
    time.sleep(0.1)
# When you have a Chinese account, you should code it 1 Down, or you'll make a mistake 
login(" Chinese account ".decode('utf-8'),' password ')
#login(" English account ",' password ')
#buy_on_time('2017-05-06 21:30:01')

There are many time. sleep() in the code, mainly to prevent the following elements from being read if the webpage is not refreshed. As slider verification may occur in Taobao, I let the user enter the account and password and sleep for 3 seconds. But after you get rid of that time. sleep(3), you get slider validation, I don't know why.


Related articles: