require 'curl' curl = CURL.new page = curl.get("http://www.sina.com.cn") puts page.encode("utf-8","gbk")
这段代码执行会产生错误:
a.rb:4:in encode': "\xAC\xC3" from GBK to UTF-8 (Encoding::UndefinedConversionError)
from a.rb:4:in
而下边的就能正常解析 require "open-uri" open("http://www.sina.com.cn") { | x | while line = x.gets puts line.encode('utf-8','gbk') end } 不明白是为什么,求教。