Python2.X和Python3.X中的urllib区别

Urllib是Python提供的一个用于操作URL的模块,在Python2.X中,有Urllib库,也有Urllib2库,在Python3.X中Urllib2合并到了Urllib中,我们爬取网页的时候,经常需要用到这个库。下面总结了Urllib相关模块中从Python2.X到Python3.X的常见的一些变动。

  

在Python2.X中使用import urllib2——对应的,在Python3.X中会使用import urllib.request,urllib.error。


在Python2.X中使用import urllib——对应的,在Python3.X中会使用import urllib.request,urllib.error,urllib.parse。


在Python2.X中使用import urlparse——对应的,在Python3.X中会使用import urllib.parse。


在Python2.X中使用import urllib2——对应的,在Python3.X中会使用import urllib.request,urllib.error。


在Python2.X中使用urllib2.urlopen——对应的,在Python3.X中会使用urllib.request.urlopen。


在Python2.X中使用urllib.urlencode——对应的,在Python3.X中会使用urllib.parse.urlencode。


在Python2.X中使用urllib.quote——对应的,在Python3.X中会使用urllib.request.quote。


在Python2.X中使用cookielib.CookieJar——对应的,在Python3.X中会使用http.CookieJar。


在Python2.X中使用urllib2.Request——对应的,在Python3.X中会使用urllib.request.Request
  

posted @ 2017-06-09 13:57  淋哥  阅读(1035)  评论(0编辑  收藏  举报