current position:Home>The rich woman's best friend asked me to write her a Taobao double 11 rush purchase script in Python, which can only be arranged
The rich woman's best friend asked me to write her a Taobao double 11 rush purchase script in Python, which can only be arranged
2022-01-30 13:48:07 【White and white I】
Little knowledge , Great challenge ! This article is participating in “ A programmer must have a little knowledge ” Creative activities
This article has participated in 「 Digging force Star Program 」 , Win a creative gift bag , Challenge creation incentive fund
What kind of experience is it to have a sister who cuts off one hand every double 11 ? I didn't learn Python When , Just let me give her all kinds of tickets , Now learn a little Python, Just let me write her a rush script , Ah ! What can I do , If you are used to it, you can only spoil it .
After my unremitting research , The experiment is finally finished ! You guys are welcome to show me if you can optimize , Welcome to point out my shortcomings .
To enter the body ...
Our climbing goal
Website : TaoBao
Tool use
development tool :pycharm
development environment :python3.7, Windows10
Using the toolkit :selenuim
Demand analysis
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 .
Analysis of project ideas
selenium Installation configuration
selenium yes Python Tool library for automated testing , Some environment drivers need to be configured
selenium install
pip install selenium
Copy code
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 :
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
Project analysis
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")
Copy code
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
Easy source sharing
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")
Copy code
I am white and white i, A program Yuan who likes to share knowledge ️
Interested can pay attention to my official account : White and white Python【 Thank you very much for your praise 、 Collection 、 Focus on 、 Comment on , One key three links support 】
copyright notice
author[White and white I],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201301348057818.html
The sidebar is recommended
- Python code reading (Part 44): find the location of qualified elements
- Elegant implementation of Django model field encryption
- 40 Python entry applet
- Pandas comprehensive application
- Chapter 2: Fundamentals of python-3 character string
- Python pyplot draws a parallel histogram, and the x-axis value is displayed in the center of the two histograms
- [Python crawler] detailed explanation of selenium from introduction to actual combat [1]
- Curl to Python self use version
- Python visualization - 3D drawing solutions pyecharts, Matplotlib, openpyxl
- Use python, opencv's meanshift and CAMSHIFT algorithms to find and track objects in video
guess what you like
-
Using python, opencv obtains and changes pixels, modifies image channels, and trims ROI
-
[Python data collection] university ranking data collection
-
[Python data collection] stock information collection
-
Python game development, pyGame module, python takes you to realize a magic tower game from scratch (2)
-
Python solves the problem of suspending execution after clicking the mouse in CMD window (fast editing mode is prohibited)
-
[Python from introduction to mastery] (II) how to run Python? What are the good development tools (pycharm)
-
Python type hints from introduction to practice
-
Python notes (IX): basic operation of dictionary
-
Python notes (8): basic operations of collections
-
Python notes (VII): definition and use of tuples
Random recommended
- Python notes (6): definition and use of lists
- Python notes (V): string operation
- Python notes (IV): use of functions and modules
- Python notes (3): conditional statements and circular statements
- Python notes (II): lexical structure
- Notes on python (I): getting to know Python
- [Python data structure series] - tree and binary tree - basic knowledge - knowledge point explanation + code implementation
- [Python daily homework] Day7: how to combine two dictionaries in an expression?
- How to implement a custom list or dictionary in Python
- 15 advanced Python tips for experienced programmers
- Python string method tutorial - how to use the find() and replace() functions on Python strings
- Python computer network basics
- Python crawler series: crawling global airport information
- Python crawler series: crawling global port information
- How to calculate unique values using pandas groupby
- Application of built-in distribution of Monte Carlo simulation SciPy with Python
- Gradient lifting method and its implementation in Python
- Pandas: how to group and calculate by index
- Can you create an empty pandas data frame and fill it in?
- Python basic exercises teaching! can't? (practice makes perfect)
- Exploratory data analysis (EDA) in Python using SQL and Seaborn (SNS).
- Turn audio into shareable video with Python and ffmpeg
- Using rbind in python (equivalent to R)
- Pandas: how to create an empty data frame with column names
- Talk about quantifying investment using Python
- Python, image restoration in opencv - CV2 inpaint
- Python notes (14): advanced technologies such as object-oriented programming
- Python notes (13): operations such as object-oriented programming
- Python notes (12): inheritance such as object-oriented programming
- Chapter 2: Fundamentals of python-5 Boolean
- Python notes (11): encapsulation such as object-oriented programming
- Python notes (10): concepts such as object-oriented programming
- Gradient lifting method and its implementation in Python
- Van * Python | simple crawling of a site course
- Chapter 1 preliminary knowledge of pandas (list derivation and conditional assignment, anonymous function and map method, zip object and enumerate method, NP basis)
- Nanny tutorial! Build VIM into an IDE (Python)
- Fourier transform of Python OpenCV image processing, lesson 52
- Introduction to python (III) network request and analysis
- China Merchants Bank credit card number recognition project (Part I), python OpenCV image processing journey, Part 53
- Python practice - capture 58 rental information and store it in MySQL database