淘宝秒杀(Python源代码)

所需程序及库

1.Python3
2.selenium库
3.webdriver
4.Chrome内核浏览器(谷歌,360,qq等)

源码

from selenium import webdriver
import datetime

# 淘宝购物车网址
url = "https://cart.taobao.com/cart.htm"

# 加载浏览器驱动
browser = webdriver.Chrome(executable_path="d:/chromedriver.exe")
browser.get(url)

# 已登录则全选,否则等待登录
while True:
    try:
        if browser.find_element_by_xpath('//*[@id="J_SelectAll1"]/div/label'):
            browser.find_element_by_xpath('//*[@id="J_SelectAll1"]/div/label').click()
            print("已经全选")
            break
    except:
        print("等待登录...")
        continue


while True:
    time1 = datetime.datetime.now().strftime("%H:%M:%S.%f")
    # 判断时间
    if time1 >= '11:55:00':  # 开始时间
        # 点击结算
        browser.find_element_by_id('J_Go').click()
        while True:
            try:
                if  browser.find_element_by_class_name('go-btn'):
                    # 点击提交订单
                    browser.find_element_by_class_name('go-btn').click()
                    while True:
                        try:
                            if browser.find_element_by_xpath('// *[ @ id = "payPassword_container"] / div'):
                                # 输入支付 密码
                                browser.find_element_by_xpath('// *[ @ id = "payPassword_container"] / div').send_keys('990607') # 支付密码
                                # 点击支付
                                browser.find_element_by_xpath('//*[@id="J_authSubmit"]').click()
                                break
                        except:
                            continue
            except:
                continue

你可能感兴趣的:(淘宝秒杀(Python源代码))