tenderlove/nokogiri — Issue #592: Invalid html encode fetched by Nokigiri
Author: frankel
Created: 2012-01-06 10:33:33+00:00
State: open

I use Kaminari to parse an html. I need both the content and image tags in the page, so I use `inner_html` instead of `content` method. But the value returned by `content` is encoded correct, while wrongly encoded by `inner_html`. One note, the page is in Chinese and not use UTF-8 encoding.

Here is my code:

# encoding: utf-8
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'iconv'

doc = Nokogiri::HTML.parse(open("http://www.sfzt.org/advise/view.asp?id=536"), nil, 'gb18030')

doc.css('td.font_info').each do |link|
puts link.content
#Or puts link.inner_html
end