title: How can I prepend the 'http://' protocol to a url when necessary?
body: <p>I need to parse an URL. I'm currently using urlparse.urlparse() and urlparse.urlsplit().</p>
  
  <p>The problem is that i can't get the "netloc" (host) from the URL when it's not present the scheme.
  I mean, if i have the following URL:</p>
  
  <blockquote>
    <p>www.amazon.com/Programming-Python-Mark-Lutz/dp/0596158106/ref=sr_1_1?ie=UTF8&amp;qid=1308060974&amp;sr=8-1</p>
  </blockquote>
  
  <p>I can't get the netloc: www.amazon.com</p>
  
  <p>According to python docs:</p>
  
  <blockquote>
    <p>Following the syntax specifications in
    RFC 1808, urlparse recognizes a netloc
    only if it is properly introduced by
    ‘//’. Otherwise the input is presumed
    to be a relative URL and thus to start
    with a path component.</p>
  </blockquote>
  
  <p>So, it's this way on purpose. But, i still don't know how to get the netloc from that URL.</p>
  
  <p>I think i could check if the scheme is present, and if it's not, then add it, and then parse it. But this solution doesn't seems really good.</p>
  
  <p>Do you have a better idea?</p>
  
  <p><strong>EDIT:</strong>
  Thanks for all the answers. But, i cannot do the "startswith" thing that's proposed by Corey and others. Becouse, if i get an URL with other protocol/scheme i would mess it up. See:</p>
  
  <p>If i get this URL:</p>
  
  <pre><code>ftp://something.com
  </code></pre>
  
  <p>With the code proposed i would add "http://" to the start and would mess it up.</p>
  
  <p><strong>The solution i found</strong></p>
  
  <pre><code>if not urlparse.urlparse(url).scheme:
     url = "http://"+url
  return urlparse.urlparse(url)
  </code></pre>
  
  <p>Something to note:</p>
  
  <p>I do some validation first, and if no scheme is given i consider it to be http://</p>