1. Install PyCharm. There are many online tutorials.

2. Install the Selenium library.

Selenium supports many browsers, and I chose Firefox.

Since I am in a Python3 environment and have PIP installed with it, selenium is installed directly using PIP

Installation method:

— Open CMD;

— Enter Python36/Scripts (find the directory below);

— Enter the command PIP install selenium;

— Press Enter to wait for automatic installation;

— If the last line of code says “Successfully install Selenium -xx”, the installation is successful.

 

 

3. The FireBug plug-in

FireBug is a firefox plugin that allows you to quickly locate code elements. Selenium focuses on locating elements, and only after locating elements in place can you proceed to the next step.

Installation method:

Open the Firefox browser and click the button in the upper right corner

— Click add-ons

— Click Expand

– search firebug

Click Install and restart the browser

— The test installation is successful. Press F12 to display the following screen, indicating that Firebug has been successfully installed

 

Install the GeckoDriver (in Windows).

The file is linked below.

Usage:

1, download complete decompression;

2. Place geckodriver in the path of the browser executable

 

3. Add to environment variables

 

5. Set the pycharm

Start by creating a project

 

Open PyCharm -> Open File -> Click Setting -> click the Settings button on the far right

Click Add in Virtualenv Environment and System Interpreter and select the python runtime folder given in this article. Location is an empty working folder.

 

Open PyCharm -> Open File -> Click Setting

Set Project Interpreter to the file given in this article, or to your own python runtime

 

6. Create a Python file

Enter the following program:

# -*- coding: utf-8 -*-

from selenium import webdriver

driver = webdriver.Firefox()

driver.get(“www.baidu.com”)

The result is as follows:

 

Successfully set up the environment.

7. Taobao second kill program

#! /usr/bin/env python

# -*- coding: utf-8 -*-

# 2018/09/05

# Taobao second kill script, scan code login version

import os

from selenium import webdriver

import datetime

import time

from os import path

from selenium.webdriver.common.action_chains import ActionChains

 

d = path.dirname(__file__)

abspath = path.abspath(d)

 

driver = webdriver.Firefox()

driver.maximize_window()

 

def login():

Open the Taobao login page and scan the code to log in

driver.get(“www.taobao.com”)

time.sleep(3)

If driver.find_element_by_link_text(” dear, please login “):

Driver.find_element_by_link_text (” dear, please log in “).click()

 

Print (” Please scan code in 30 seconds “)

time.sleep(30)

 

driver.get(“cart.taobao.com/cart.htm”)

time.sleep(3)

Click on the Select All button in your shopping cart

# if driver.find_element_by_id(“J_CheckBox_939775250537”):

# driver.find_element_by_id(“J_CheckBox_939775250537”).click()

# if driver.find_element_by_id(“J_CheckBox_939558169627”):

# driver.find_element_by_id(“J_CheckBox_939558169627”).click()

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’))

 

def buy(buytime):

while True:

now = datetime.datetime.now().strftime(‘%Y-%m-%d %H:%M:%S.%f’)

# Compare the time and click settle when the time is up

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 (‘ Submit order ‘).click()

except:

Time. Sleep (0.1)

print(now)

Time. Sleep (0.1)

 

if __name__ == “__main__”:

# times = input(” please input time: “)

# time format: “2018-09-06 11:20:00.000000”

login()

Buy (” the 2018-10-22 18:55:00. 000000 “)

The above procedures are selected with reference to the corresponding elements of the CORRESPONDING HTML source code. Examples are as follows:

 

J_SelectAll1 corresponds to the following: