Python: Possible to use urlparse to parse domain from cgi bin URL
Question: I have the following **input string** :

    
    
    /cgi-bin/ivw/CP/dbb_ug_sp;?r=http%3A//www.some-super-domain.de/forum/viewtopic.php%3Ff%3D2%26t%3D18564%26start%3D75&d=76756.76050130278
    

I wanted to use `urlparse()` to **get the domain** , but getting the `netloc`
attribute returns an empty string in this case.

How can I extract the domain (bestcase: without www)?

**Output wanted:** some-super-domain.de

Please note: Sometimes there is **no www** in above input string!


Answer: I think `urlparse` dot give you what you want you can use this :

    
    
    m=re.search(r'(?<=www\.)[a-zA-Z\-]+\.[a-zA-Z]+',s)
    print m.group(0)
    

result:

    
    
    some-super-domain.de
    

try it [HERE](http://regex101.com/#python) !

so if you use `urlparse` the result is this :

    
    
    s='/cgi-bin/ivw/CP/dbb_ug_sp;?r=http%3A//www.some-super-domain.de/forum/viewtopic.php%3Ff%3D2%26t%3D18564%26start%3D75&d=76756.76050130278'
    
    from urlparse import urlparse
    o = urlparse(s)
    print o
    

result:

    
    
    ParseResult(scheme='', netloc='', path='/cgi-bin/ivw/CP/dbb_ug_sp', params='', query='r=http%3A//www.some-super-domain.de/forum/viewtopic.php%3Ff%3D2%26t%3D18564%26start%3D75&d=76756.76050130278', fragment='')
    

So in this result you can access to domain with `o.query` but it isn't what
you want it's contain extra character !

    
    
    >>>print o.query
    >>>r=http%3A//www.some-super-domain.de/forum/viewtopic.php%3Ff%3D2%26t%3D18564%26start%3D75&d=76756.76050130278
    

