2013-07-03 52 views
3

我得到了一個簡單的登錄腳本,它可以正常工作,直到它嘗試使用像åäö等字母。我沒有得到任何的錯誤,但登錄只是失敗,所以我認爲編碼混淆了它。我該如何解決這個問題?提前致謝!紅寶石機械化登錄問題(編碼)

# encoding: utf-8 

require 'nokogiri' 
require 'mechanize' 
agent = Mechanize.new 

page = agent.get("site.com/login.php") 

form = page.forms.last 
form.namn = 'Johan.Björk' 
form.losen = 'password' 
button = form.button_with(:value => "Login") 
site = agent.submit(form, button) 

if site.body.include? "Wrong User/Password" 
    puts 'fail' 
else 
    puts 'success' 
end 
+0

什麼是錯誤?腳本的編碼是什麼? – pguardiario

+0

錯誤是,登錄失敗的用戶與他們的名字åäö,但我知道憑據是正確的。正如它在頂部所示,編碼是utf-8? –

+0

你有沒有試過latin1? – pguardiario

回答

0

嘗試:

# encoding: utf-8 

require 'nokogiri' 
require 'mechanize' 
agent = Mechanize.new 

page = agent.get("site.com/login.php") 

form = page.forms.last 
form.namn = 'Johan.Björk' 
form.losen = 'password' 
site = agent.submit(form, form.buttons.first) 

if site.body.include? "Wrong User/Password" 
    puts 'fail' 
else 
    puts 'success' 
end 

還要確保您運行的是最新版本。