# !/usr/bin/env python# -*- coding: utf-8 -*-# /11/09# 淘宝秒杀脚本,扫码登录版from selenium import webdriverimport datetimeimport timedef login():# 打开淘宝登录页,并进行扫码登录browser.get("")time.sleep(3)if browser.find_element_by_link_text("亲,请登录"):browser.find_element_by_link_text("亲,请登录").click()print("请在15秒内完成扫码")time.sleep(15)print("请在30秒内输入秒杀地址:")urlName = input()time.sleep(30)# browser.get("/cart.htm")browser.get(urlName)time.sleep(3)now = datetime.datetime.now()print('login success:', now.strftime('%Y-%m-%d %H:%M:%S'))def buy(times, choose):# 点击购物车里全选按钮if choose == 2:print("请手动勾选需要购买的商品")while True:now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')# 对比时间,时间到的话就点击结算if now > times:if choose == 1:while True:try:if browser.find_element_by_id("J_LinkBuy"):# if browser.find_element_by_link_text("立即购买"):# browser.find_element_by_link_text("立即购买").click()browser.find_element_by_id("J_LinkBuy").click()time.sleep(0.5)# browser.find_element_by_id("J_LinkBuy").click()if browser.find_element_by_link_text("提交订单"):browser.find_element_by_link_text("提交订单").click()breakexcept:print("出现下单错误,请重新尝试!")# 点击结算按钮while True:try:if browser.find_element_by_link_text("结 算"):browser.find_element_by_link_text("结 算").click()print("结算成功")breakexcept:passwhile True:try:if browser.find_element_by_link_text('提交订单'):browser.find_element_by_link_text('提交订单').click()now1 = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')print("抢购成功时间:%s" % now1)except:print("再次尝试提交订单")time.sleep(0.01)if __name__ == "__main__":print("请提前五分钟制定时间。")times = input("请输入抢购时间,格式如(-01-01 11:20:00.000000):")# 时间格式:"-09-06 11:20:00.000000"browser = webdriver.Chrome()browser.maximize_window()print(browser)login()choose = int(1)# choose = int(input("到时间自动勾选购物车请输入“1”,否则输入“2”:"))buy(times, choose)
如果觉得《淘宝抢券python代码 能够对实时抢券和清空购物车。》对你有帮助,请点赞、收藏,并留下你的观点哦!