Watir给Amazon.cn充礼品卡

写个脚本去尝试不花钱给自己的Amazon.cn账号充礼品卡,碰碰运气。

#encoding: UTF-8                                          #添加这一行才可以处理中文
require 'rubygems'                                        #gem install xxx --no-ri --no-rdoc
require 'timeout'
require 'watir-webdriver'

def randCharOfLength(len)                                 #产生随机任意长度的数
    chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
    str = ""
    1.upto(len) {|i| str << chars[rand(chars.size-1)]}
    return str
end
b = Watir::Browser.new(:firefox, {:profile => 'default'})
b.goto "https://www.amazon.cn/ap/signin/477-4175358-2686144?_encoding=UTF8&openid.assoc_handle=cnflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=900&openid.return_to=https%3A%2F%2Fwww.amazon.cn%2Fgp%2Fcss%2Fgc%2Fpayment%2Fredeem-gc-balance%2F477-4175358-2686144%3Fie%3DUTF8%26*Version*%3D1%26*entries*%3D0&showRmrMe=1"
b.text_field(:id,"ap_email").set "your_amazon.cn_account"
b.text_field(:id,"ap_password").set "your_amazon.cn_password"
b.div(:id,"ap_signin1a_signin_button_row").span(:class,"ap_col2").button(:id, "signInSubmit").click
gift_code = randCharOfLength(4).upcase + '-' + randCharOfLength(6).upcase + '-' + randCharOfLength(5).upcase
b.text_field(:class,"gcTextInput").set gift_code            #礼品卡号的格式为:XXX-XXXXXX-XXXX
b.button(:name,"applytoaccount").click 

b.span(:class, "gcMMIcon gcMMErrorIcon").wait_until_present
 while (b.span(:class, "gcMMIcon gcMMErrorIcon").exists?) do
     gift_code = randCharOfLength(4).upcase + '-' + randCharOfLength(6).upcase + '-' + randCharOfLength(4).upcase
     b.text_field(:class,"gcTextInput").set gift_code       #礼品卡号的格式为:XXX-XXXXXX-XXXX
     b.button(:name,"applytoaccount").click
     sleep(1)
     if b.checkbox(:id, 'rememberMe').exists? then 
        b.text_field(:id,"ap_password").set "your_amazon.cn_password"
        b.checkbox(:id, 'rememberMe').set
        b.div(:id,"ap_signin1a_signin_button_row").span(:class,"ap_col2").button(:id, "signInSubmit").click
        gift_code = randCharOfLength(4).upcase + '-' + randCharOfLength(6).upcase + '-' + randCharOfLength(5).upcase
        b.text_field(:class,"gcTextInput").set gift_code    #礼品卡号的格式为:XXX-XXXXXX-XXXX
        b.button(:name,"applytoaccount").click 
        b.span(:class, "gcMMIcon gcMMErrorIcon").wait_until_present
      end 
 end
代码仅供娱乐参考,切勿用于不当用途。经本人测试,有被封号风险,也有可能摊上法律责任,劝君不要冲动贪小便宜。

Comments !