views:

287

answers:

1

Hello, the following code raises the aforementioned error, how can I fix that?

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)

Just in case, here is the full description of an error on my box

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>'

And BTW this solution doesn't work

A: 

Looks like the solution is to rewrite the gem a little so that it converts the encoding of the page to utf-8 on initializing a new page, changing @encoding var to utf-8 and storing the original encoding in another file, and making changes necessary to force the gem to use original encoding on forming a query

roddik