htano / summary_dev

development social summary service
1 stars 0 forks source link

[ContentsExtractor] livedoor blog対応 #202

Closed toru1055 closed 10 years ago

toru1055 commented 10 years ago

現状ドメインごとに設定できるけど、livedoorブログは最初のディレクトリまで指定できるようにする。 http://blog.livedoor.jp/itsoku/

toru1055 commented 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>

これの対処をする

toru1055 commented 10 years ago

記事のエンコードがeuc-jpだとわかっている場合は、

html = open(url, "r:binary") do |f|
  f.read.encode("utf-8", "euc-jp", :invalid => :replace, :undef => :replace)
end

こうする

toru1055 commented 10 years ago

contentsExtractorにopenuriのメソッドを作って、エンコーディングごとにopenするのがいい気がする