urlparse :
url = ’http://netloc/path;param?query=arg#frag’
parsed = urlparse(url)
print parsed
結果:ParseResult(scheme=’http’, netloc=’netloc’, path=’/path’,params=’param’, query=’query=arg’, fragment=’frag’)
urlsplit()
parsed
= urlsplit(url)
print parsed
結果:SplitResult(scheme=’http’, netloc=’user:pwd@NetLoc:80’,path=’/p1;param/p2;param’, query=’query=arg’, fragment=’frag’)注意,urlsplit比urlparse的數組少了一項!
urldefrag()
過濾掉了fragment
parsed = urlparse(url)
print parsed.geturl() 結果爲原url
urlunparse url重構,丟棄url多餘的部分
urljoin
print urljoin(’http://www.example.com/path/file.html’,’anotherfile.html’) 結果:http://www.example.com/subpath/file.html
print urljoin(’http://www.example.com/path/file.html’,’../anotherfile.html’)結果:http://www.example.com/path/subpath/file.