python淘宝秒杀
需要火狐驱动#!/usr/bin/env python# -*- coding: utf-8 -*-# 2019/11/13#作者:刘运超# 淘宝秒杀脚本,扫码登录版import sysimport osfrom selenium import webdriverimport datetimeimport timefrom os import pathfrom seleni...
·
需要火狐驱动
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 2019/11/13
#作者:刘运超
# 淘宝秒杀脚本,扫码登录版
import sys
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)
try:
driver = webdriver.Firefox()
driver.maximize_window()
except:
print("请安装火狐浏览器")
print("五秒后关闭程序")
time.sleep(5)
sys.exit()
def login():
# 打开淘宝登录页,并进行扫码登录
try:
driver.get("https://www.taobao.com")
except:
print("请检查网络环境")
print("五秒后关闭程序")
time.sleep(5)
sys.exit()
time.sleep(2)
if driver.find_element_by_link_text("亲,请登录"):
driver.find_element_by_link_text("亲,请登录").click()
print("请在15秒内完成扫码")
time.sleep(15)
try:
driver.get("https://cart.taobao.com/cart.htm")
except:
print("超出登陆时间,五秒后关闭程序")
time.sleep(5)
sys.exit()
time.sleep(2)
# 点击购物车里全选按钮
# 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()
try:
if driver.find_element_by_id("J_SelectAll1"):
driver.find_element_by_id("J_SelectAll1").click()
except:
print("空购物车,关闭程序")
sys.exit()
now = datetime.datetime.now()
print('login success:', now.strftime('%Y-%m-%d %H:%M:%S'))
def buy(bug_time):
if driver.find_element_by_id("J_Go"):
while True:
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
if now > bug_time:
try:
#now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
driver.find_element_by_id("J_Go").click()
# print("点击结算时间",now)
driver.find_element_by_link_text('提交订单').click()
# now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
print("点击提交订单时间",now)
print("提交成功,程序结束,祝您购物愉快")
time.sleep(5)
break
except:
pass
#time.sleep(0.01)
print(now)
#time.sleep(0.01)
def print_time():
print("正在打开火狐浏览器,请稍后。。。")
li_now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
print("当前时间是:",li_now)
print("茅台抢购时间如下:","2019-11-12 22:00:00.000000")
if __name__ == "__main__":
print_time()
times = input("请输入抢购时间:")
login()
buy(times)
更多推荐
已为社区贡献3条内容
所有评论(0)