ということで今のところ以下のように落ち着いてる。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
require 'nkf' | |
def get_title(url) | |
url.gsub!(Regexp.new("[^#{URI::PATTERN::ALNUM}\/\:\?\=&~,\.\(\)#]")) {|match| ERB::Util.url_encode(match)} | |
read_data = NKF.nkf("--utf8", open(url).read) | |
Nokogiri::HTML.parse(read_data, nil, 'utf8').xpath('//title').text | |
end | |
p get_title 'http://example.com/hoge/huga' |
0 コメント:
コメントを投稿