Manga Srinivas Rao Baipalli Manga Srinivas Rao Baipalli - 1 year ago 146
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.

Answer Source

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!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download