title: Python if no AttributeError
body: <p>I have a small script that returns the title of a webpage</p>
  
  <pre><code>title = BeautifulSoup(urllib2.urlopen(URL)).title.string
  </code></pre>
  
  <p>But not all websites specify a <code>&lt;title&gt;</code> tag, in which case my script returns</p>
  
  <pre><code>AttributeError: 'NoneType' object has no attribute 'string'
  </code></pre>
  
  <p>Is there a way to have the <code>title</code> variable equal to the title if there is a title on the webpage?</p>
  
  <p>I am tried</p>
  
  <pre><code>if BeautifulSoup(urllib2.urlopen(url)).title.string.strip():
      print BeautifulSoup(urllib2.urlopen(url)).title.string.strip()
  else:
      print url
  </code></pre>
  
  <p>But it still raises the AttributeError error</p>