Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
运行以下代码时出现以下错误:
invalid byte sequence in UTF-8 (ArgumentError)
编码:
require 'hpricot' require 'open-uri' doc = open('http://www.amazon.co.jp/') {|f| Hpricot(f.read) } puts doc.to_html
Hpricot 无法解析日语内容。有关解决此问题的任何建议?
该网站似乎没有使用 UTF-8: <meta http-equiv="content-type" content="text/html; charset=Shift_JIS" />。
<meta http-equiv="content-type" content="text/html; charset=Shift_JIS" />
试试这个:
open('http://www.amazon.co.jp/') {|f| Hpricot(f.read.encode("UTF-8")) }