title: How to remove new line and linefeed from title tags of a page? (Google App Engine - Python)
body: <p>I have this code to extract title:</p>
  
  <pre><code>soup = BeautifulSoup.BeautifulSoup(urllib.urlopen(url))
  title = str(soup.html.head.title.string).lstrip("\r\n").rstrip("\r\n")
  </code></pre>
  
  <p>Some sites add return or newline before and after title tags (why?) and to remove them I added </p>
  
  <pre><code>.lstrip("\r\n").rstrip("\r\n")
  </code></pre>
  
  <p>This works for instance with <a href="http://www.readwriteweb.com/" rel="nofollow noreferrer">http://www.readwriteweb.com/</a> but not with <a href="http://poundwire.com/" rel="nofollow noreferrer">http://poundwire.com/</a>. Can you tell why one is working and the other is not?</p>
  
  <p><strong>Update</strong></p>
  
  <p>Following up on comment by Steve Jessop; I'm using <code>replace</code> and it seems to work:</p>
  
  <pre><code>title = str(soup.html.head.title.string).replace("\t", "").replace("\r", "").replace("\n", "")
  </code></pre>
  
  <p>Let me know if there is a better way. Thanks.</p>
  
  <p><strong>Update 2</strong></p>
  
  <p>I found this <a href="https://stackoverflow.com/questions/1898656/remove-whitespace-in-python-using-string-whitespace/1898835#1898835">answer</a> and it seems better:</p>
  
  <pre><code>title = " ".join(str(soup.html.head.title.string).split())
  </code></pre>