Get Root Domain of Link

后端 未结 7 1407
半阙折子戏
半阙折子戏 2021-01-17 08:13

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?

相关标签:
7条回答
  • 2021-01-17 09:09

    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('//')
        is_root_domain = tail.split('/', 1)[0] if '/' in tail else url
        # printing or returning is_root_domain will give you what you seek
        print(is_root_domain)
    
    is_root('http://www.techcrunch.com/')
    
    0 讨论(0)
提交回复
热议问题