python學習---urlparse模塊

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.












發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章