python怎么抢东西_python实现京东秒杀抢购商品操作

#!/usr/bin/env python##-*- coding:utf-8 -*-

from selenium importwebdriverimportdatetimeimporttime

driver=webdriver.Firefox()defauto_buy(username, password, purchase_list_time):print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "打开登陆界面")

driver.get("https://passport.jd.com/new/login.aspx")print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "开始填写账号密码")

driver.find_element_by_link_text("账户登录").click()

driver.find_element_by_name("loginname").send_keys(username)

driver.find_element_by_name("nloginpwd").send_keys(password)

driver.find_element_by_id("loginsubmit").click()print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "手动拼图验证")

time.sleep(10) #此处睡眠时间用来手动拼图验证

print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),"登陆成功")print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "等待时间到达抢购时间:",purchase_list_time, "......")whileTrue:

count=0for buytime inpurchase_list_time:

nowtime= datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')if nowtime ==buytime:try:

count+= 1

print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "开始第 %s 次抢购......"%count)print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "打开购物车并选中商品")

driver.get("https://cart.jd.com/cart.action") #打开购物车并选中商品

print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "点击去结算")

driver.find_element_by_link_text("去结算").click() #去结算

print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "点击提交订单")

time.sleep(5) #提交订单前必须等待几秒【感觉跟电脑性能快慢有关,不卡的电脑可以适当降低尝试】

driver.find_element_by_id('order-submit').click() #提交订单

print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),"订单提交成功,请前往订单中心待付款付款")print("")continue

exceptException as e:print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "抢购出现异常,重新抢购:", e)continuetime.sleep(0.001)

purchase_list_time=["2020-10-16 00:00:00","2020-10-16 00:00:01","2020-10-16 00:00:02","2020-10-16 00:00:03","2020-10-16 00:00:04","2020-10-16 00:00:05",

]

auto_buy('账号', '密码', purchase_list_time)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值