How can I retrieve the page title of a webpage using Python?

This my Answer to the stackoverflow question: How can I retrieve the page title of a webpage using Python?:

I'll always use lxml for such tasks. You could use beautifulsoup as well.

import lxml.html
t = lxml.html.parse(url)
print t.find(".//title").text