In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Today, the editor will share with you the relevant knowledge points about how to achieve the second kill system in Python. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Demand Analysis & preparation in advance
The demand is actually very simple, normal shopping. Our daily shopping process is as follows:
Before we begin, we need to prepare the running environment of the program.
Environment
System: Windows/Mac OS
Python version: 3.7.2
In order for the program to simulate every step of our operation, I'd like to introduce a sharp weapon: Selenium
Students in the Selenium test should feel very kind. It is an automated testing tool through which we can drive browsers to perform specific actions, such as click, drop-down, etc., WYSIWYG.
Installation of Selenium
Run the following command:
Pip install selenium
However, if we want to use Selenium to successfully call the Chrome browser to complete the corresponding operation, we also need a medium to interface with the browser. Xiaoming uses a Chrome browser this time, so it needs to be driven by ChromeDriver.
Installation of ChromeDriver
We need to find the corresponding version of ChromeDriver according to our Chrome browser version, and then download and decompress it according to the platform type of your computer system.
Windows: place it under the Scripts folder under the Python installation path
Mac OS: put it under / usr/local/bin
At the end of the environment configuration, Xiaoming wrote a python script to verify whether the environment was built successfully:
From selenium import webdriver
# Open the Chrome browser
If _ _ name__ = ='_ _ main__':
Browser = webdriver.Chrome ()
After running the code, if we successfully open a new browser, it will prove that our environment is installed, and then we can shop happily.
Script writing
Compared with the above Taobao shopping flow chart, the corresponding code is as follows:
Open the Taobao website
Browser.get ("https://www.taobao.com")"
Log in
First, jump to the landing page.
Browser.find_element_by_link_text ("dear, please log in"). Click ()
Select the QR code for login method
Browser.find_element_by_class_name (icon-qrcode) .click ()
After scanning the code successfully with your mobile phone, proceed to the next step.
After logging in successfully, open the shopping cart
Browser.get ("https://cart.taobao.com/cart.htm")"
Check the goods
Browser.find_element_by_id (J_SelectAll1) .click ()
It is recommended to select all, but if you have more shopping carts and do not want to buy them all, manually check the items you want to place the order for now.
Settlement
Browser.find_element_by_link_text (settlement). Click ()
Submit an order
Browser.find_element_by_link_text ('submit order'). Click ()
As long as the order is placed successfully, there is no need to worry about the next payment, as long as it is paid within the specified time. The above is the complete shopping process. So how does the second kill come true?
The realization of second kill
The idea is actually very simple, which is to add a judgment of time on the basis of normal shopping: if the current time reaches the specified time, the order will be triggered. To obtain the current time, you need to use the built-in module datetime. The code is as follows:
Import datetime
Now = datetime.datetime.now (). Strftime ('% Y-%m-%d% Hstrftime% MRV% S.% f') above is all the content of this article "how to implement the second kill system in Python". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.