Hello everyone , I'm spicy .
A friend of spicy bar recently complained to me ： Girlfriend is addicted to Taobao rush shopping and can't extricate herself , When I don't sleep at night, I rush to buy it regularly , What a loser .
They are all good friends. Spicy strips must help , It's just a regular rush to buy , Empty the shopping cart regularly , This is called arrangement .
Website ： TaoBao
development tool ：pycharm development environment ：python3.7, Windows10 Using the toolkit ：selenuim
Our goal is to kill Taobao's orders , There are several key points , First you need to log in to Taobao , Secondly, you need to prepare the order , Finally, the order should be submitted quickly at the appointed time .
selenium yes Python Tool library for automated testing , Some environment drivers need to be configured selenium install
pip install selenium
Selenium Once installed , It can't be used directly , It needs to dock with the browser . Here Chrome Browser as an example . If you want to use Selenium A successful call Chrome Browser to complete the corresponding operation , Need to pass through ChromeDriver To drive . link ：
https://chromedriver.storage.googleapis.com/index.html According to their own chorme Version select the installed driver version
Once the download is complete , decompression , Place it in Python Under installation path python In the folder
Try to pass through selenium Open Taobao Homepage , Verify successful installation
from selenium import webdriver driver = webdriver.Chrome() driver.maximize_window() driver.get("https://www.taobao.com")
adopt xpath Locate and select the login tab , Buying scripts need to know what you're buying first
The way to log in is optional （ You can log in with your account password , You can also scan the code to log in , Spicy bar logs in here by scanning the code ）
Click the shopping cart after successful login , Select the product data you need （ You can select all , You can manually check ）
Click the settlement button
Set a settlement time , The time you need to place an order
Wait for time to come Click the submit order button
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : BaiChuan # @File : Taobao rush .py from selenium import webdriver import datetime import time driver = webdriver.Chrome() driver.maximize_window() def login(): # Open the Taobao login page , And scan the code to log in driver.get("https://www.taobao.com") time.sleep(3) if driver.find_element_by_link_text(" Pro - , Please log in "): driver.find_element_by_link_text(" Pro - , Please log in ").click() print(" Please be there. 30 Scan code in seconds ") time.sleep(30) driver.get("https://cart.taobao.com/cart.htm") time.sleep(3) # 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() now = datetime.datetime.now() print('login success:', now.strftime('%Y-%m-%d %H:%M:%S:%f')) def buy(buytime): while True: now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') print(" current time " + now) # Compare time , When the time comes, click settlement if now > buytime: try: # Click the settlement button if driver.find_element_by_id("J_Go"): driver.find_element_by_id("J_Go").click() driver.find_element_by_link_text(' place order ').click() except: time.sleep(0.1) print(now) time.sleep(0.1) if __name__ == "__main__": # times = input(" Please enter the rush time ：") # Time format ："2018-09-06 11:20:00.000000" login() buy("2021-08-24 14:30:00.000000")
The script is finished, but it doesn't seem to be finished ......