zoukankan      html  css  js  c++  java
  • 京东自动抢购机

    京东抢购页面: http://qiang.360buy.com/LimitBuy.htm

    有效时间:2011.6.1 - 2011.6.30 

    开发语言:Ruby 

    运行环境:Ruby 1.9.2 (需要安装 watir)

    文件名:qiang.rb

    运行命令:ruby qiang.rb 

    说明:可以自动抢购商品,并自动进入购物车结算,结算过程可能会遇到需要验证码情况,结算将会失败,需要手动干预。 

    require 'logger'
    require 
    'watir'

    STDOUT.sync 
    = true
    log = Logger.new(STDOUT)
    log.level = Logger::DEBUG

    $host 
    = 'qiang.360buy.com'

    auto_goto_shopping_cart         
    = true
        auto_goto_orderinfo         
    = false # depends on the previous parameter
            auto_submit_order         
    = false # depends on the previous parameter


    url 
    = "http://#{$host}/LimitBuy.htm"
    ie 
    = Watir::IE.new
    ie.
    goto url
    error_times 
    = 0
    first 
    = true
    while true do
        
    begin
            ie.refresh unless first
            ie.wait
            
            first 
    = false
            error_times 
    = 0
        rescue StandardError 
    => bang
            
    log.error "Error: #{bang}"
            
            error_times 
    += 1
            
    break if error_times > 10 
            
            redo
        
    end    
        

        
    begin
            li 
    = ie.li(:xpath, "//li[@class='fore rob'][2]")
            
            unless li.
    exists?
                
    log.info 'Checking...'
                redo
            
    end
            
            # OK, QIANG NOW

            target 
    = li.links[1].href
            
    log.info target
            
            
    if auto_goto_orderinfo
                li.links
    [1].click
            
    else
                li.links
    [1].click_no_wait
            
    end

            
    log.info '-> Going to the InitCart page...'        
            
            
    log.info '########################################################################################'    
            
            
    begin
                
                #ie2 
    = Watir::IE.attach(:title, '商品已成功加入购物车'.encode!('gbk'))
                ie2 
    = Watir::IE.attach(:url, target)
                
    if ie2.nil?
                    
    log.warn 'ie2 is null.'
                
    else
                    
    if auto_goto_shopping_cart
                        ie2.link(:id, 
    'GotoShoppingCart').click 
                        
    log.info '-> going to the shopping cart page...'
                        
                        
    if auto_goto_orderinfo                        
                            ie3 
    = Watir::IE.attach(:url, "http://jd2008.360buy.com/purchase/shoppingcart_pop.aspx?backurl=http://#{$host}/LimitBuy.htm")            
                            ie3.link(:id, 
    'gotoOrderInfo').click
                            
    log.info '-> going to the order confirm page...'
                            
                            
    if auto_submit_order
                                ie4 
    = Watir::IE.attach(:url, 'http://jd2008.360buy.com/purchase/orderinfo_pop_main.aspx')
                                
    if ie4.image(:id, 'OrderCheckCodeImg').exists?
                                    
    log.info 'No way!!! need validation code to submit the order.'
                                
    else                            
                                    ie4.button(:id, 
    'submit').click
                                    
    log.info 'Order is submited.'
                                
    end
                            
    end
                        
    end
                    
    end
                
    end
            rescue StandardError 
    => bang
                
    log.error "Error: #{bang}"
            
    end
            
            
    log.info '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'
            
            
    break
        rescue StandardError 
    => bang
            
    log.error "Error: #{bang}"
        
    end

    end 

  • 相关阅读:
    CCF 201712-4
    图论_最短路径
    图论_查并集
    let和const
    Promise
    实现表单label两端对齐
    始终让footer在底部
    react——使用this.setState({ })修改state状态值
    react——css样式
    react脚手架
  • 原文地址:https://www.cnblogs.com/yyw84/p/2085221.html
Copyright © 2011-2022 走看看