Nokogiri, open-uri, and Unicode Characters

前端 未结 8 2034
故里飘歌
故里飘歌 2020-11-30 01:56

I\'m using Nokogiri and open-uri to grab the contents of the title tag on a webpage, but am having trouble with accented characters. What\'s the best way to deal with these

8条回答
  •  无人及你
    2020-11-30 02:25

    Try setting the encoding option of Nokogiri, like so:

    require 'open-uri'
    require 'nokogiri'
    doc = Nokogiri::HTML(open(link))
    doc.encoding = 'utf-8'
    title = doc.at_css("title")
    

提交回复
热议问题