How to reliable get the title of a web page?


In one of my forms, i want the user to enter a url and then the title of
the associated web page to be automatically filled in, by looking it up
from the page.

Currently i’m doing that using hpricot, which can pull out the contents
of the title tag, but it only pulls it out as text. This works most of
the time, but a lot of the time i get “HTML HR TAG” or something

Does anyone know how i can reliably get at the displayed title of any
web page?