How can I retrieve the page title of a webpage using Python?
<p>How can I retrieve the page title of a webpage (title html tag) using Python?</p>

<p>Here's a simplified version of <a href="http://stackoverflow.com/a/51242/4279">@Vinko Vrsalovic's answer</a>:</p>

<pre><code>import urllib2
from BeautifulSoup import BeautifulSoup

soup = BeautifulSoup(urllib2.urlopen("https://www.google.com"))
print soup.title.string
</code></pre>

<p>NOTE:</p>

<ul>
<li><p><em>soup.title</em> finds the first <em>title</em> element <strong>anywhere</strong> in the html document</p></li>
<li><p><em>title.string</em> assumes it has only <strong>one</strong> child node, and that child node is a <strong>string</strong></p></li>
</ul>

<p>For <a href="http://www.crummy.com/software/BeautifulSoup/bs4/doc/">beautifulsoup 4.x</a>, use different import:</p>

<pre><code>from bs4 import BeautifulSoup
</code></pre>
