Get subdomain from URL using Python

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

For example, the address is:

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

8条回答
  •  自闭症患者
    2020-12-20 13:15

    What you are looking for is in: http://docs.python.org/library/urlparse.html

    for example: ".".join(urlparse('http://www.my.cwi.nl:80/%7Eguido/Python.html').netloc.split(".")[:-2])

    Will do the job for you (will return "www.my")

提交回复
热议问题