How to get the domainname (name+TLD) from a URL in python

后端 未结 4 713
温柔的废话
温柔的废话 2021-01-14 04:51

I want to extract the domain name(name of the site+TLD) from a list of URLs which may vary in their format. for instance: Current state---->what I want

mai         


        
4条回答
  •  情歌与酒
    2021-01-14 05:21

    Using python tld

    https://pypi.python.org/pypi/tld

    $ pip install tld

    from tld import get_tld
    print get_tld("http://www.google.co.uk/some-page/some-sub-page/")
    'google.co.uk'
    

提交回复
热议问题