Python, url parsing
Question: I have url e.g: "<http://www.nicepage.com/nicecat/something>" And I need parse
it, I use:

    
    
    from urlparse import urlparse
    url=urlparse("http://www.nicepage.com/nicecat/something")
    #then I have:
    #url.netloc() -- www.nicepage.com
    #url.path() -- /nicecat/something
    

But I want to delete "www", and parse it little more. I would like to have
something like this:

    
    
    #path_without_www -- nicepage.com
    #list_of_path -- list_of_path[0] -> "nicecat", list_of_path[1] -> "something"
    


Answer: How about this:

    
    
    import re
    from urlparse import urlparse
    
    url = urlparse('http://www.nicepage.com/nicecat/something')
    url = url._replace(netloc=re.sub(r'^(www.)(.*)', r'\2', url.netloc))
    

The regex strips the 'www.' from the beginning of the netloc. From there you
can parse it more as you wish.

