get site name from a URL in python

前端 未结 3 1824
没有蜡笔的小新
没有蜡笔的小新 2020-12-11 12:00

I am new to Python and it seems to have a lot of nice functions that I don\'t know about. What function can I use to get the root site name? For example, how would I get

3条回答
  •  半阙折子戏
    2020-12-11 12:34

    The much overlooked urlparse module:

    from urlparse import urlparse
    scheme, netloc, path, params, query, fragment = urlparse("http://www.faqs.org/docs/diveintopython/kgp_commandline.html")
    print netloc
    

提交回复
热议问题