zoukankan      html  css  js  c++  java
  • python实现京东秒杀

    # _*_coding:utf-8_*_  
    from selenium import webdriver
    import datetime  
    import time
    
    
    driver = webdriver.Chrome(executable_path='chromedriver.exe')
    
    def login(uname, pwd):
        driver.get("http://www.jd.com")
        driver.find_element_by_link_text("你好,请登录").click()
    
        driver.find_element_by_link_text("账户登录").click()
        driver.find_element_by_name("loginname").send_keys(uname)
        driver.find_element_by_name("nloginpwd").send_keys(pwd)
        driver.find_element_by_id("loginsubmit").click()
    
        driver.get("https://cart.jd.com/cart.action")
    
        driver.find_element_by_link_text("去结算").click()
        now = datetime.datetime.now()
        print('login success:',now.strftime('%Y-%m-%d %H:%M:%S'))
    
    
    # buytime = '2016-12-27 22:31:00' 
    def buy_on_time(buytime):
        while True:
            now = datetime.datetime.now()
            if now.strftime('%Y-%m-%d %H:%M:%S') == buytime:
                while True:
                    try:
                        driver.find_element_by_id('order-submit').click()
                    except Exception as e:
                        time.sleep(0.1)
                print ('purchase success',now.strftime('%Y-%m-%d %H:%M:%S'))
                time.sleep(0.5)
    
    
    # entrance
    login('username', 'password')
    buy_on_time('2017-01-01 14:00:01')
  • 相关阅读:
    你自己不优秀,就算认识再多优秀人又有何用
    史玉柱和他老同学的一段故事
    哪有雪中送碳,都是锦上添花
    围城之困
    心已死,梦前行
    一位销售高手逼单经历!
    Python--函数return多个值
    Python--内置函数
    Python--小程序
    Python--递归
  • 原文地址:https://www.cnblogs.com/Erick-L/p/7391034.html
Copyright © 2011-2022 走看看