我有一个简单的登录脚本,对于像åäö等字母,一切都很顺利,直到尝试使用它们时。我没有收到任何错误信息,但是登录失败了,因此我认为编码出现了问题。我该如何解决这个问题?提前感谢您!
# 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