Python urlparse — extract domain name without subdomain

前端 未结 7 968
南笙
南笙 2020-12-01 02:30

Need a way to extract a domain name without the subdomain from a url using Python urlparse.

For example, I would like to extract \"google.com\" from a f

7条回答
  •  醉梦人生
    2020-12-01 03:19

    from tld import get_tld
    from tld.utils import update_tld_names
    update_tld_names()
    
    result=get_tld('http://www.google.com')
    print 'https://'+result
    

    Input: http://www.google.com

    Result: google.com

提交回复
热议问题