From: 7stud -- Date: 2008-01-27T13:42:18+09:00 Subject: Re: Extracting Data from a Webpage Tj Superfly wrote: > Hello everyone. > > I was wondering if anyone knew a way to extract the web page title off > of a specific URL that you input into a program? > > I give it the URL, say www.google.com. It then gives me "Google" - it's > title. > > Then also, is there anyway that the program could extract the next 5 > characters - after a certain phrase that doesn't change on the webpage? > > Thanks for your help in advance! You can do something like this: require 'open-uri' url = "http://www.google.com" open(url) do |f| f.each do |line| if md_obj = /(.*)<\/title>/.match(line) puts md_obj[1] end if md_obj = /type=(.{6})/.match(line) puts md_obj[1] end end end Ruby also has various html parsing libraries that allow you to search html documents by tag name, tag position, etc. -- Posted via http://www.ruby-forum.com/.