Answer by Praveen Kumar for Get Root Domain of Link
this simple code will get the root domain name from all valid URLs.from urllib.parse import urlparseurl = 'https://www.google.com/search?q=python'root_url = urlparse(url).scheme +'://'+...
View ArticleAnswer by Hg0428 for Get Root Domain of Link
This worked for me:def get_sub_domains(url): urlp = parseurl(url) urlsplit = urlp.netloc.split(".") l = [] if len(urlsplit) < 3: return l for item in urlsplit: urlsplit = urlsplit[1:]...
View ArticleAnswer by Jason Martinez for Get Root Domain of Link
You dont need a package, or any of the complexities people are suggesting to do this, it's as simple as below and tweaking to your liking.def is_root(url): head, sep, tail = url.partition('//')...
View ArticleAnswer by ospider for Get Root Domain of Link
def get_domain(url): u = urlsplit(url) return u.netlocdef get_top_domain(url): u""">>> get_top_domain('http://www.google.com')'google.com'>>>...
View ArticleAnswer by darklow for Get Root Domain of Link
Following script is not perfect, but can be used for display/shortening purposes. If you really want/need to avoid any 3rd party dependencies - especially remotely fetching and caching some tld data I...
View ArticleAnswer by Mohsin Aljiwala for Get Root Domain of Link
General structure of URL:scheme://netloc/path;parameters?query#fragmentAs TIMTOWTDI motto: Using urlparse,>>> from urllib.parse import urlparse # python 3.x>>> parsed_uri =...
View ArticleAnswer by azam for Get Root Domain of Link
______Using Python 3.3 and not 2.x________I would like to add a small thing to Ben Blank's answer.from urllib.parse import quote,unquote,urlparseu=unquote(u) #u= URL e.g....
View ArticleAnswer by Joe J for Get Root Domain of Link
This worked for my purposes. I figured I'd share it. ".".join("www.sun.google.com".split(".")[-2:])
View ArticleAnswer by Ben Blank for Get Root Domain of Link
Getting the hostname is easy enough using urlparse:hostname = urlparse.urlparse("http://www.techcrunch.com/").hostnameGetting the "root domain", however, is going to be more problematic, because it...
View ArticleGet Root Domain of Link
I have a link such as http://www.techcrunch.com/ and I would like to get just the techcrunch.com part of the link. How do I go about this in python?
View Article