Manga Srinivas Rao Baipalli Manga Srinivas Rao Baipalli - 4 months ago 40
Python Question

python URL parse type

How to display type of URL from the Given url as a string?
String =

and it should display edu.


I've written this code to get the domain type

from urlparse import urlparse
dom = ''
parsed_uri = urlparse( '' )
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!