618 In the past the , I did an earth shaking event the other day , It is estimated that this great event is what many little friends want to do . I used it python Rush to buy Taobao products , little does one think
Well , I am the bravest . On the idea of buying and code , I will introduce it in detail in this article , Those who are interested can look down !!!
1. Project environment
2. Analysis of a treasure rush purchase process
3. Program implementation ideas
4. Code practice and sorting
• operating system :Windows 10
Python Exchange of learning Q Group :903971231####
• development environment :python3.7
•IDE:Pycharm
• Automation module :Selenium
• Installation command :pip install selenium
• Browser version :Google Chrome 99.0.4844.51
• Browser driven version :ChromeDriver 99.0.4844.51
Be careful : The browser driven version should be consistent with the browser version !
I have prepared for you 2022 Abreast of the times Python Free learning materials 、 Code 、 Tutorials, etc , Directly add a group to receive .
1. Login website
2. The shopping cart selects the items to be snapped up
3. Settle the purchase
4. place order
The key : Quickly complete the previous process , When the order enters the submission page , The payment time does not affect the rush purchase .
The shopping process is fixed and unchanged , Therefore, you can edit the steps of the shopping process with code and submit them to selenium To automate .
Project structure : Drive direct copy into the project root path
1、 Import the corresponding class library to realize the operation of the browser
from selenium import webdriverimport datetime
import time
# Automatically open the browser and maximize the window driver =
webdriver.Chrome()driver.maximize_window()
Execute the above code , The browser will automatically open and display as follows , It proves that we have started to manipulate the browser through code .
driver.get('https://www.taobao.com')
if driver.find_element_by_partial_link_text(' Pro - , Please log in '):
driver.find_element_by_partial_link_text(' Pro - , Please log in ').click()
# Jump to the shopping cart page driver.get('https://cart.taobao.com/cart.htm')
# Look for all options and check if driver.find_element_by_id("J_SelectAll1"):
driver.find_element_by_id("J_SelectAll1").click()
def buy(buy_time): #buy_time Time of purchase
while True:
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
print(' current time :%s'%now)
# Judge whether the rush time is reached
if now>buy_time:
try:
driver.find_element_by_partial_link_text(' junction count ').click()
except:
pass
# Compare time , Cycle order submission
while True:
try:
if driver.find_element_by_link_text(' place order '):
driver.find_element_by_link_text(' place order ').click()
print(f" Panic buying , Please pay as soon as possible ")
except:
print(f" Try to submit the order again ")
time.sleep(0.01)
In this way, you can rush to buy goods at fixed time through the set period of time !
print(f" Try to submit the order again ")
time.sleep(0.01)
[ Outside the chain picture transfer in ...(img-oA7Q06eg-1648366756452)]
** In this way, you can rush to buy goods at fixed time through the set period of time !**
In this way, you can rush to buy goods at fixed time through the set period of time !
About today's article , This is all my thinking , Give me a little heart if you like , Your support is my motivation , If you don't know anything about the article, you can send a private letter
Yo! !! See you in the next chapter !!!