Parsing hostname and port from string or url

前端 未结 5 2086
迷失自我
迷失自我 2021-02-07 00:54

I can be given a string in any of these formats:

  • url: e.g http://www.acme.com:456

  • string: e.g www.acme.com:456, www.acme.com 456, or www.acme.co

5条回答
  •  青春惊慌失措
    2021-02-07 01:29

    >>> from urlparse import urlparse   
    >>> aaa = urlparse('http://www.acme.com:456')
    
    >>> aaa.hostname  
    'www.acme.com'
    
    >>> aaa.port   
    456
    >>> 
    

提交回复
热议问题