Skip to content

Instantly share code, notes, and snippets.

@todashuta
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save todashuta/a30fa2eae2fffef53fce to your computer and use it in GitHub Desktop.

Select an option

Save todashuta/a30fa2eae2fffef53fce to your computer and use it in GitHub Desktop.
URLからタイトルを取得する (Macのサービスに入れて右クリックで使う用)
# 与えられたURLのタイトル (<title>(.*?)</title>) を取得し、
# "TITLE" {given-URL} という形式で出力する
require 'open-uri'
require 'nkf'
ARGF.each do |url|
title = NKF.nkf('-w', open(url).read.match(%r{<title>(.*?)</title>}m)[1])
print %("#{title.strip}" #{url.strip})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment