2009-10-07 246 views

回答

16

Iconv

require 'iconv' 
i = Iconv.new('UTF-8','LATIN1') 
a_with_hat = i.iconv("\xc2") 
4

看你的標籤,我想你想是這樣的:

require 'rubygems' 
require 'open-uri' 
require 'nokogiri' 
require 'iconv' 

file = open(your_uri) 
doc = Nokogiri::HTML(Iconv.conv('utf-8', 'latin1', file.readlines.join("\n"))) 
doc.xpath(your_xpath) 

如果你不知道什麼字符集的URI的用途,您可以使用file.charset來獲取字符集而不是​​。