Programming」カテゴリーアーカイブ

プログラミング全般に関するカテゴリーです。

URLのパース

PythonのurlparseでURLの分解ができます。
簡単なURL解析をしたい場合に便利です。

使い方

>>> import urlparse  
>>> url = urlparse.urlparse('http://www.example.com/python/sample01.html')  
ParseResult(scheme='http', netloc='www.example.com', path='/python/sample01.html', params='', query='', fragment='')  
>>> url.scheme  
'http'  
>>> url.netloc  
'www.example.com'  
>>> url.geturl()  
'http://www.example.com/python/sample01.html'