2017-04-10 48 views
0
require "mechanize" 

    a = Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' } 
    a.get('http://erp.jecrcuniversity.edu.in:8084/jecrc_academia/') do |page| 
     page.form_with(name: "loginForm") do |f| 
     f.userId = ARGV[0] 
     f.password1 = ARGV[1] 
     end.submit 
    end 

    a.get('http://122.15.3.5:8084/jecrc_webguru/login.do') do |page| 
     pp page 
    end 

我想登錄,然後重定向到頁面,但它不斷重定向我登錄頁面。我也試圖做到這一點,但我仍然有同樣的問題。Ruby機械化登錄表單提交錯誤

# jecrc_form = page.form('loginForm') 
    # username_field = jecrc_form.field_with(:name => 'userId') 
    # username_field.value = ARGV[0]; 
    # password_field = jecrc_form.field_with(:name => 'password1') 
    # password_field.value = ARGV[1] 
    # jecrc_form.click_button 

我的形式漂亮的打印是:

{forms 
     #<Mechanize::Form 
     {name "loginForm"} 
     {method "POST"} 
     {action "/jecrc_academia/CommonLoginCheck.do 
     ;sessionid=1EA144A84FA0B3845126723B95634B4F"}    
     {fields 
     [hidden:0x126d9e0 type: hidden name: currentTime value: ] 
     [text:0x126d88c type: text name: userId value: ] 
     [hidden:0x126d738 type: hidden name: password value: ] 
     [field:0x126d5e4 type: password name: password1 value: ]} 
     {radiobuttons} 
     {checkboxes} 
     {file_uploads} 
     {buttons [button:0x126d47c type: button name: value: Login]}>}> 

回答

1

下面是瀏覽器發送:

  • currentTime的:MTQ5MTg3OTYzNDAwMA ==
  • 用戶名:FOO
  • 密碼:37b51d194a7513e45b56f6524f2d51f2
  • password1:bar

密碼看起來像是md5,currentTime是時間戳的base64(本例中爲1491879634000)。

+0

是我的問題類似於此:http://stackoverflow.com/questions/2151171/how-to-log-into-vbulletin-3-6-using-mechanize-ruby –

+0

他們都有md5在答案所以它有點類似 – pguardiario

+0

@pguardiaro謝謝:) –