#coding:utf-8
#import scrapy
from selenium import webdriver
import time
import datetime
class JDQUAN(object):
def __init__(self,url):
self.driver=webdriver.Firefox()
self.driver.get(url)
def login_jd(self,num,pwd):
self.driver.find_element_by_link_text('你好,请登录').click()
time.sleep(5)
self.driver.find_element_by_link_text('账户登录').click()
time.sleep(3)
self.driver.find_element_by_id('loginname').send_keys(num)
self.driver.find_element_by_id('nloginpwd').send_keys(pwd)
time.sleep(3)
self.driver.find_element_by_id('loginsubmit').click()
def buy_on_time(self,buytime,quan_link):
while True:
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
pre = datetime.datetime.strptime(buytime, '%Y-%m-%d %H:%M:%S') - datetime.timedelta(seconds=40)
pre = pre.strftime('%Y-%m-%d %H:%M:%S')
if pre == now:
self.driver.refresh()
if now == buytime:
#self.driver.find_element_by_class_name(quan_link).click()
self.driver.get(quan_link)
time.sleep(3)
print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
print('successful!!!')
break
def start(self,buytime,quan_link):
num='****'
pwd='********'
self.login_jd(num,pwd)
self.buy_on_time(buytime,quan_link)
jd=JDQUAN('https://sale.jd.com/act/L8mwRbMeIap3kCAg.html')
jd.start('2018-01-24 20:05:00','https://coupon.jd.com/ilink/couponSendFront/send_index.action?key=3472bd7400804b01b6d5bd8162289d85&roleId=10117929&to=https://sale.jd.com/act/L8mwRbMeIap3kCAg.html')
#超市