From: Heesob Park Date: 2009-04-28T09:54:52+09:00 Subject: Re: Get title from URL? 2009/4/28 Cisco Ri : > Heesob Park wrote: >> 2009/4/24 Cisco Ri : >>> Anybody have a code snippet that extracts the title from the tag >>> from a given URL? >> >> require 'rubygems' >> require 'mechanize' >> title = WWW::Mechanize.new.get('http://google.com').title >> => "Google" >> >> >> Regards, >> Park Heesob > > I used this method for a while, and it was fine for most sites. > However, with wikipedia.org it errored out with a 403 Forbidden error. > The Hpricot/open-uri method works for most sites, including > wikipedia.org, but for thesixtyone.com (Javascript intensive site) it > errors out with a 500 Internal Server error. You can work around like this: require 'rubygems' require 'mechanize' agent = WWW::Mechanize.new agent.user_agent_alias = 'Mac Safari' title = agent.get('http://wikipedia.org').title Regards, Park Heesob