Get subdomain from URL using Python

前端 未结 8 1068
孤城傲影
孤城傲影 2020-12-20 13:00

For example, the address is:

Address = http://lol1.domain.com:8888/some/page

8条回答
  •  时光取名叫无心
    2020-12-20 13:35

    We can use https://github.com/john-kurkowski/tldextract for this problem...

    It's easy.

    >>> ext = tldextract.extract('http://forums.bbc.co.uk')
    >>> (ext.subdomain, ext.domain, ext.suffix)
    ('forums', 'bbc', 'co.uk')
    

提交回复
热议问题