nishimura.clubnishimura.club

Python で ドメインの取得(URL操作)

作成日
2021-07-19
更新日
2021-07-19

基本形

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

参考

Related

Tags

Python

Share