找不到Ruby Mechanize代码转换器

时间:2012-07-19 22:55:30

标签: ruby character-encoding mechanize mechanize-ruby

我尝试了很多东西:

Mechanize on Ruby 1.9.3 encoding issueHow do I convert from a Mechanize::File object to a Mechanize::Page object?

但我一直得到的错误是

.rvm/gems/ruby-1.9.3-p194/gems/mechanize-2.0.1/lib/mechanize/util.rb:59:in `encode': code converter not found (UTF-8 to UTF8) (Encoding::ConverterNotFoundError)
    from /home/dhahn/.rvm/gems/ruby-1.9.3-p194/gems/mechanize-2.0.1/lib/mechanize/util.rb:59:in `encode_to'
    from /home/dhahn/.rvm/gems/ruby-1.9.3-p194/gems/mechanize-2.0.1/lib/mechanize/util.rb:45:in `from_native_charset'
    from /home/dhahn/.rvm/gems/ruby-1.9.3-p194/gems/mechanize-2.0.1/lib/mechanize/form.rb:187:in `from_native_charset'
    from /home/dhahn/.rvm/gems/ruby-1.9.3-p194/gems/mechanize-2.0.1/lib/mechanize/form.rb:181:in `block in proc_query'
    from /home/dhahn/.rvm/gems/ruby-1.9.3-p194/gems/mechanize-2.0.1/lib/mechanize/form.rb:180:in `map'
    from /home/dhahn/.rvm/gems/ruby-1.9.3-p194/gems/mechanize-2.0.1/lib/mechanize/form.rb:180:in `proc_query'
    from /home/dhahn/.rvm/gems/ruby-1.9.3-p194/gems/mechanize-2.0.1/lib/mechanize/form.rb:206:in `block in build_query'
    from /home/dhahn/.rvm/gems/ruby-1.9.3-p194/gems/mechanize-2.0.1/lib/mechanize/form.rb:198:in `each'
    from /home/dhahn/.rvm/gems/ruby-1.9.3-p194/gems/mechanize-2.0.1/lib/mechanize/form.rb:198:in `build_query'
    from /home/dhahn/.rvm/gems/ruby-1.9.3-p194/gems/mechanize-2.0.1/lib/mechanize/form.rb:249:in `request_data'
    from /home/dhahn/.rvm/gems/ruby-1.9.3-p194/gems/mechanize-2.0.1/lib/mechanize.rb:618:in `post_form'
    from /home/dhahn/.rvm/gems/ruby-1.9.3-p194/gems/mechanize-2.0.1/lib/mechanize.rb:520:in `submit'
    from /home/dhahn/.rvm/gems/ruby-1.9.3-p194/gems/mechanize-2.0.1/lib/mechanize/form.rb:167:in `submit'
    from /home/dhahn/user-management/test_script/EWI.rb:73:in `add_ext'
    from testewi.rb:15:in `<main>'

我有一个使用mechanize的类,它适用于ruby 1.8.7,但我需要它与1.9.3一起使用,因为其余的rails应用程序是在1.9.3中。对不起,我现在有点混乱,所以如果我需要包含其他内容请告诉我。这也是我在这里的第一个问题。

1 个答案:

答案 0 :(得分:1)

您正在访问的网页可能错误地描述了其编码。

我认为修复方法是通过执行类似

之类的操作来改变它
page.encoding = "utf-8"