【发布时间】:2017-04-11 10:24:31
【问题描述】:
我有非常简单的代码:
require 'rubygems'
require 'mechanize'
URL = 'http://yandex.ru'
agent = Mechanize.new
page = agent.get(URL)
# page.encoding => UTF-8
# page.body.encoding => ASCII-8BIT
page.body.include?("Карты")
在该代码的最后一行,Ruby 返回了一个错误:
in `include?': incompatible character encodings: ASCII-8BIT and UTF-8 (Encoding::CompatibilityError)
来自“How to get Mechanize to auto-convert body to UTF8?”的解决方案没有帮助。我应该怎么做才能解决它?
【问题讨论】:
标签: ruby encoding utf-8 mechanize