若隻使用python3.X, 下面可以不看了, 記住有個urllib的庫就行了
python3.X 有這些庫名可用: urllib, urllib3, httplib2, requests
urllib和urllib2的主要差別:
1.urllib2可以接受Request對象,為URL設定頭資訊, 修改使用者代理,設定cookie等, urllib隻能接受一個普通的URL.
2.urllib提供一些比較原始基礎的方法而urllib2沒有這些, 比如 urlencode
urllib官方文檔的幾個例子:
urllib2的幾個官方文檔的例子:
httplib 和 httplib2 httplib 是http用戶端協定的實作,通常不直接使用, urllib是以httplib為基礎 httplib2 是第三方庫, 比httplib有更多特性。
httplib比較底層,一般使用的話用urllib和urllib2即可。
這裡urllib成了一個包, 此包分成了幾個子產品,
python2.X 中的 urllib.urlopen()被廢棄, urllib2.urlopen()相當于python3.X中的urllib.request.urlopen()
幾個官方例子:
python2.X中的httplib被重命名為 http.client
使用 2to3 工具轉換源碼時, 會自動處理這幾個庫的導入.
總的來說, 使用python3, 記住隻有urllib, 想要更簡潔好用就用requests, 但不夠通用 .
參考:
<a href="http://www.hacksparrow.com/python-difference-between-urllib-and-urllib2.html" target="_blank">http://www.hacksparrow.com/python-difference-between-urllib-and-urllib2.html</a>
<a href="http://blog.csdn.net/lxlzhn/article/details/10474281" target="_blank">http://blog.csdn.net/lxlzhn/article/details/10474281</a>
<a href="http://www.codefrom.com/paper/%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3urllib%E3%80%81urllib2%E5%8F%8Arequests" target="_blank">http://www.codefrom.com/paper/%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3urllib%E3%80%81urllib2%E5%8F%8Arequests</a>
<a href="http://www.cnblogs.com/wly923/archive/2013/05/07/3057122.html" target="_blank">http://www.cnblogs.com/wly923/archive/2013/05/07/3057122.html</a>
<a href="http://stackoverflow.com/questions/2018026/should-i-use-urllib-urllib2-or-requests" target="_blank">http://stackoverflow.com/questions/2018026/should-i-use-urllib-urllib2-or-requests</a>
<a href="http://stackoverflow.com/questions/3305250/python-urllib-vs-httplib" target="_blank">http://stackoverflow.com/questions/3305250/python-urllib-vs-httplib</a>
<a href="http://hustcalm.me/blog/2013/11/14/httplib-httplib2-urllib-urllib2-whats-the-difference/" target="_blank">http://hustcalm.me/blog/2013/11/14/httplib-httplib2-urllib-urllib2-whats-the-difference/</a>
沒有整理與歸納的知識,一文不值!高度概括與梳理的知識,才是自己真正的知識與技能。 永遠不要讓自己的自由、好奇、充滿創造力的想法被現實的架構所束縛,讓創造力自由成長吧! 多花時間,關心他(她)人,正如别人所關心你的。理想的騰飛與實作,沒有别人的支援與幫助,是萬萬不能的。
本文轉自wenglabs部落格園部落格,原文連結:http://www.cnblogs.com/arxive/p/6194368.html,如需轉載請自行聯系原作者