DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Extracting Web Page Title

11.29.2006
| 5807 views |
  • submit to reddit
        Easy extracting html 'title' element from an url

require 'open-uri'

URI.parse('http://google.es').open do |f|
	f.each {|l| if md = (/<title>\s*(.*)\s*<\/title>/iu).match(l) then print md[1] end }
end