title: Find http:// and or www. and strip from domain. leaving domain.com
body: <p>I'm quite new to python. I'm trying to parse a file of URLs to leave only the domain name.</p>
  
  <p>some of the urls in my log file begin with http:// and some begin with www.Some begin with both.</p>
  
  <p>This is the part of my code which strips the http:// part. What do I need to add to it to look for both http and www. and remove both?</p>
  
  <pre><code>line = re.findall(r'(https?://\S+)', line)
  </code></pre>
  
  <p>Currently when I run the code only http:// is stripped. if I change the code to the following:</p>
  
  <pre><code>line = re.findall(r'(https?://www.\S+)', line)
  </code></pre>
  
  <p>Only domains starting with both are affected.
  I need the code to be more conditional.
  TIA</p>
  
  <p>edit... here is my full code...</p>
  
  <pre><code>import re
  import sys
  from urlparse import urlparse
  
  f = open(sys.argv[1], "r")
  
  for line in f.readlines():
   line = re.findall(r'(https?://\S+)', line)
   if line:
    parsed=urlparse(line[0])
    print parsed.hostname
  f.close()
  </code></pre>
  
  <p>I mistagged by original post as regex. it is indeed using urlparse.</p>