tags:

views:

41

answers:

2

Hi,

Im some cases when I use open to get a web page in ruby the content of the page has an encoding error. Exemple :

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

Chars like ç and ã are replaced by "?"

How can I get the right chars ?

thanks.

A: 

this seems to work:

require 'iconv'
i = Iconv.new('UTF-8','LATIN1')
i.iconv(open('http://google.com.br').read)
jordinl
That will work as long as the encoding is consistent throughout the document. HTML from a site that generates its own content is *usually* consistent. HTML from a site that aggregates content from multiple places can end up being all over the map, for instance, Google.
Greg