preface
Hello, friends, happy Chinese Valentine’s Day! Although today is Tanabata, but the pain is still in the small make up honestly overtime! So did you guys get everything ready for your date? Xiaobian but a week in advance of the second to kill a few gifts, today good to give to his girlfriend! If you forget what you didn’t prepare, you have to learn a good wave, and you can save what you have prepared for the next holiday! After all, such technology is not foolproof! Today to share the tutorial is through Python to achieve the purchase of JINGdong goods! No more nonsense, start today’s case sharing!
Problem analysis
I think you should have used a mobile phone to grab the kind of second bargain goods, waiting for a long time, the time is not easy, but in the end nothing! The purchase failed, and when the order was submitted, it was found to be out of stock, thus confirming that JD had grabbed the mark by submitting the order, sometimes as if the success was achieved by paying. Pre-sale items can be added to the cart, but they are not optional, so they must be checked first during the automatic buying process.
For example, similar to the picture, then the next is a snap up the process! The general process of BUYING jingdong is: login account → enter the shopping cart → select the goods to buy → click to settle → click to submit the order → choose the payment method and pay. Based on this situation, python code is used to automatically log in to JD account, automatically slide the verification code for verification, automatically check the shopping cart and submit the order, and the rest of the payment operation is carried out manually.
Basic situation
1. The Python interpreter and Pycharm have been installed, and the image source has been switched and bound.
2. Anaconda and Pycharm have been installed and bound to the Python interpreter provided by Anaconda. The image source has been switched and bound to the Pycharm.
Any of them can be satisfied
Focus on
Selenium is a Python automated testing tool. The Selenium toolkit allows you to perform simple and practical actions such as clicking on a browser web page and downloading content. This tool is a must!
In the case of using a separate Python interpreter, use the command line CD to go to the Scripts directory in the interpreter installation path and run the code PIP install Selenium to install.
If you are using Anaconda’s built-in Python interpreter, open the Anaconda Prompt and run the activate Root code to enter the base environment (some versions are already opened in the base environment and do not need to perform this step). Next, run the code PIP Install Selenium to install.
Wait until the installation is complete and run Python to enter the interactive environment. Run the import Selenium code if no error is reported, the installation is successful.
Download the Edge browser driver
You can use the Edge browser, Chrome, FireFox, etc., but you need to download the corresponding driver.
This driver is to download with their own version of the same line, such as 3.9 version, then the driver is the same
Login to JD.com
Open the Edge browser and maximize the window to enter the LOGIN interface of JD.com.
Select the Account login option, automatically enter the user name and password, and then click Login.
Slide authentication login
Due to jd.com’s security restrictions, after clicking on the login, you need to perform a slide verification to complete the login. The slide verification code itself consists of two images, one as a small slidable slider and the other as a background missing the slider structure.
Firstly, two images of sliding verification code are obtained, and then saved to local after graying
Then matchTemplate function in OpencV is used to get the similarity matrix of the slider image on the background.
Result = cv2.matchTemplate(background, slideblock, cv2.tm_cCOeff_normed
The element index function UNRAvel_index in NUMPY was used to get the index of the maximum matching degree in the original similarity matrix.
_, distance = np.unravel_index(result.argmax(), result.shape) # Get the distance to move
Note that the indexing coordinate system in this function is slightly different from the general understanding.
The sim moves the slider faster and faster to the specified position. Due to the safety control of JINGdong, a certain slider movement strategy must be adopted to avoid being detected manually. In the actual experiment, the correct number of steps for sliding verification is also uncertain, about 1 to 10 steps.
Automatic purchase of goods
After login, click on my shopping cart to open another browser page.
Select all items in the cart, click checkout and submit your order.
Complete implementation source code
Because this above does not use the code block! So xiaobian in the way of screenshots to show you, you need the complete code or packaged script can be left in the comment area!
That’s the end of it
Complete project code
If you use to get words can directly take away, in my QQ technology communication group group number: 948351247 (pure technical communication and resource sharing, advertising does not enter) to self-help take away
Click here to claim