Python实现京东秒杀功能代码
程序员文章站
2023-11-28 20:54:10
本文实例为大家分享了python实现京东秒杀功能的具体代码,供大家参考,具体内容如下
#python 3.5
#coding:utf-8
#import...
本文实例为大家分享了python实现京东秒杀功能的具体代码,供大家参考,具体内容如下
#python 3.5
#coding:utf-8 #import scrapy from selenium import webdriver import time import datetime driver = webdriver.firefox() driver.get('https:www.jd.com/') class jdlogin(object): def login_jd(self,num,pwd): driver.find_element_by_link_text('你好,请登录').click() time.sleep(10) driver.find_element_by_link_text('账户登录').click() time.sleep(3) driver.find_element_by_id('loginname').send_keys(num) driver.find_element_by_id('nloginpwd').send_keys(pwd) time.sleep(3) driver.find_element_by_id('loginsubmit').click() time.sleep(5) nowwhandle = driver.current_window_handle driver.find_element_by_link_text('我的购物车').click() allhandles = driver.window_handles for handle in allhandles: if handle != nowwhandle: driver.switch_to_window(handle)#切换至窗口 购物车页面 time.sleep(5) driver.find_element_by_link_text('去结算').click() time.sleep(4) def buy_on_time(self,buytime): while true: now = datetime.datetime.now() if now.strftime('%y-%m-%d %h:%m:%s') == buytime: driver.find_element_by_id('order-submit').click() time.sleep(3) print(now.strftime('%y-%m-%d %h:%m:%s')) print('successful!!!') time.sleep(0.5) # 返回原先到的窗口 #driver.switch_to_window(nowwhandle) def start(self,num,pwd,buytime): self.login_jd(num,pwd) self.buy_on_time(buytime) jdlogin=jdlogin() jdlogin.start('手机号','密码','秒杀时间' )
需要先将秒杀物品添加至购物车(必须为秒杀物品,秒杀无品加入购物车后结算时不需要勾选【全选框】),并提前设置默认收货地址
该代码为闲时所写,没有进一步优化,面向对象的函数也不够精简,不过功能已经实现
需要在cmd命令行安装selenium包:pip install selenium
其余包同理,需要啥下载即可
以上所述是小编给大家介绍的python实现京东秒杀功能详解整合,希望对大家有所帮助