私は次のことを行うSinatraアプリケーション(http://analyzethis.espace-technologies.com)を持っています
- HTMLページを取得する(net / http経由)
- response.bodyからNokogiriドキュメントを作成します
- いくつかの情報を抽出し、応答で送り返します。応答はUTF-8でエンコードする必要があります
そのため、www.filfan.comやwww.masrawy.comなどのwindows-1256エンコーディングを使用するサイトを読み込もうとしたときに問題が発生しました。
問題は、エラーがスローされないにもかかわらず、エンコーディング変換の結果が正しくないことです。
net / http response.body.encodingは、UTF-8に変換できないASCII-8BITを提供します
Nokogiri :: HTML(response.body)を実行し、cssセレクターを使用してページから特定のコンテンツ(たとえば、タイトルタグのコンテンツなど)を取得すると、string.encodingを呼び出すとWINDOWS-1256を返す文字列が取得されます。 。string.encode( "utf-8")を使用し、それを使用して応答を送信しますが、応答が正しくありません。
私のアプローチの何が悪いのかについての提案やアイデアはありますか?