Python Question

python URL parse type

How to display type of URL from the Given url as a string?
example:
String = http://introcs.cs.princeton.edu/python

and it should display edu.

Answer

I've written this code to get the domain type

from urlparse import urlparse
dom = ''
parsed_uri = urlparse( 'http://introcs.cs.princeton.edu/python' )
domain = '{uri.scheme}://{uri.netloc}'.format(uri=parsed_uri)
for i in range(len(domain.split('.'))):
    dom = domain.split('.')[i]

print dom

P.S. This code only works for URLs starting with a protocol, like http:// or https://

You can maybe get an idea from this. Cheers!