下面的代码引发了上述错误,我如何修复?

require 'mechanize'
m = WWW::Mechanize.new
p = m.get('http://art-mobile.com.ua/register.php')
f = p.forms.first
f.submit(f.buttons.last)

以防万一,这是我盒子上一个错误的完整描述
D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/util.rb:40:in `iconv': "Ðåãèñòðàöèÿ"... (Iconv::IllegalSequence)
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/util.rb:40:in `from_native_charset'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/form.rb:152:in `from_native_charset'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/form.rb:144:in `block in proc_query'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/form.rb:143:in `map'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/form.rb:143:in `proc_query'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/form.rb:198:in `block in build_query'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/form.rb:197:in `each'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/form.rb:197:in `build_query'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/form.rb:214:in `request_data'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize.rb:401:in `post_form'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize.rb:344:in `submit'
    from D:/ruby/lib/ruby/gems/1.9.1/gems/mechanize-0.9.3/lib/www/mechanize/form.rb:130:in `submit'
    from D:/doer.rb:8:in `<main>'

顺便说一句this solution不起作用

最佳答案

看起来解决方案是稍微重写gem,以便在初始化新页时将页的编码转换为utf-8,将@encoding var更改为utf-8并将原始编码存储在另一个文件中,并进行必要的更改以强制gem在形成查询时使用原始编码

09-20 06:16