2

I am getting output "com" instead of "google.com"

I have tried changing sites name but every site is showing "com"

from tld import get_tld

def get_domain_name(url):
    domain_name= get_tld(url)
    return domain_name

print(get_domain_name("https://www.google.com"))

I expect output to be "google.com" I have tried this code on Piaza workspace terminal

brunns
  • 2,689
  • 1
  • 13
  • 24
  • Why? TLD is to [Extract the top level domain (TLD) from the URL given](https://pypi.org/project/tld/) – Alderven Apr 19 '19 at 13:44
  • 1
    Possible duplicate of [How to extract top-level domain name (TLD) from URL](https://stackoverflow.com/questions/1066933/how-to-extract-top-level-domain-name-tld-from-url) – Bill the Lizard Apr 19 '19 at 13:45
  • 2
    "com" is the top-level domain. https://en.wikipedia.org/wiki/Top-level_domain – Bill the Lizard Apr 19 '19 at 13:46
  • 1
    I don't think it's a duplicate of those, because I don't think the OP really wants the TLD at all. See @cssko's answer. – brunns Apr 19 '19 at 13:47
  • I agree with @brunns. Would it be appropriate to edit the question to reflect what Ritik really wants, the first level domain? – cssko Apr 19 '19 at 13:53

1 Answers1

3

What you're asking for is the first level domain, so you'd use the function get_fld

    from tld import get_fld
    print(get_fld("https://www.google.com")

    >>> google.com

See the documentation at readthedocs

cssko
  • 3,027
  • 1
  • 18
  • 21