Pythonの標準ライブラリでURLを扱うクラスが用意されています。
from urllib.parse import urlparse parsed_url = urlparse('https://nishimura.club/article') print(parsed_url) # ParseResult(scheme='https', netloc='nishimura.club', path='/article', params='', query='', fragment='')
parsed_url = urlparse('https://nishimura.club/article') url = "%s://%s" % (parsed_url.scheme, parsed_url.netloc) print(url) # https://nishimura.club