0

例如,我尝试了很多东西:

Ruby 1.9.3 编码问题上的机械化以及 如何从 Mechanize::File 对象转换为 Mechanize::Page 对象?

但我不断得到的错误是

.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 中。抱歉,我现在有点混乱,所以如果我需要包含其他内容,请告诉我。这也是我在这里的第一个问题。

4

1 回答 1

1

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

我认为解决方法是自己改变它,通过做类似的事情

page.encoding = "utf-8"
于 2012-07-19T23:02:43.400 回答