Backend Development 4 min read

Building an Automated Taobao Flash‑Sale Bot with Python and Selenium

This tutorial explains how to create a Python Selenium script that automatically opens Taobao, logs in via QR code, navigates to the shopping cart, waits for a preset flash‑sale time, selects all items, and completes the checkout process.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Building an Automated Taobao Flash‑Sale Bot with Python and Selenium

The author describes a personal motivation to help his girlfriend miss fewer Double‑11 deals by writing an automated script that performs the entire purchase flow on Taobao.

Step 1 – Overall Idea : Use a program to launch a browser, go to www.taobao.com , log in, open the shopping cart, wait for the sale time, and then trigger purchase and payment automatically.

Step 2 – Import Modules :

import datetime  # module
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
import time
# full‑automation Python code
from selenium import webdriver

Step 3 – Open Browser and Log In :

times = "2021-11-04 21:00:00.00000000"
browser = webdriver.Chrome()
browser.get("https://www.taobao.com")
time.sleep(3)  # wait for page load
browser.find_element_by_link_text("亲,请登录").click()
# Prompt user to scan QR code for login
print(f"请尽快扫码登录")
time.sleep(10)
browser.get("https://cart.taobao.com/cart.htm")
time.sleep(3)

Because storing credentials in code is insecure, the script relies on manual QR‑code login.

Step 4 – Select All Items and Purchase at the Right Moment :

# Select all items in the cart
while True:
    try:
        if browser.find_element_by_id("J_SelectAll1"):
            browser.find_element_by_id("J_SelectAll1").click()
            break
    except:
        print("找不到购买按钮")

while True:
    now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
    print(now)
    if now > times:
        # Click checkout button
        while True:
            try:
                if browser.find_element_by_link_text("结 算"):
                    print("here")
                    browser.find_element_by_link_text("结 算").click()
                    print(f"主人,程序锁定商品,结算成功")
                    break
            except:
                pass
        # Click submit order button
        while True:
            try:
                if browser.find_element_by_link_text('提交订单'):
                    browser.find_element_by_link_text('提交订单').click()
                    print(f"抢购成功,请尽快付款")
            except:
                print(f"主人,我已帮你抢到商品啦,您来支付吧")
                break
        time.sleep(0.01)

The script assumes the desired products are already placed in the cart; when the preset time arrives, it selects all, proceeds to checkout, and submits the order, printing status messages throughout.

PythontaobaoautomationWeb Scrapingflash saleSeleniumscript
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.