Search code examples
rubycharacter-encodingopen-uri

Encoding error in content get from open-uri in ruby on rails


In some cases when I use open to get a web page in Ruby the content of the page has an encoding error. Example:

open("http://www.google.com.br").read

Chars like ç and ã are replaced by ?

How can I get the right chars?


Solution

  • this seems to work:

    require 'iconv'
    i = Iconv.new('UTF-8','LATIN1')
    i.iconv(open('http://google.com.br').read)