Closed toru1055 closed 10 years ago
$ URL=http://blog.livedoor.jp/dqnplus/archives/1782994.html rails runner scripts/test/contents-extractor/extractor-factory-test.rb
openuri: error was happened.
#<Encoding::UndefinedConversionError: "\xAD\xC0" from EUC-JP to UTF-8>
これの対処をする
記事のエンコードがeuc-jpだとわかっている場合は、
html = open(url, "r:binary") do |f|
f.read.encode("utf-8", "euc-jp", :invalid => :replace, :undef => :replace)
end
こうする
contentsExtractorにopenuriのメソッドを作って、エンコーディングごとにopenするのがいい気がする
現状ドメインごとに設定できるけど、livedoorブログは最初のディレクトリまで指定できるようにする。 http://blog.livedoor.jp/itsoku/