码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-06-09 15:18:15      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:网页   code   encode   url   使用   urllib2   爬取   总结   blog   

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

  

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

标签:网页   code   encode   url   使用   urllib2   爬取   总结   blog   

原文地址:http://www.cnblogs.com/xuchunlin/p/6971743.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!