urllib库对照速查表
Python2.X |
Python3.X |
urllib |
urllib.request, urllib.error, urllib.parse |
urllib2 |
urllib.request, urllib.error |
urllib2.urlopen |
urllib.request.urlopen |
urllib.urlencode |
urllib.parse.urlencode |
urllib.quote |
urllib.request.quote |
urllib2.Request |
urllib.request.Request |
urlparse |
urllib.parse |
urllib.urlretrieve |
urllib.request.urlretrieve |
urllib2.URLError |
urllib.error.URLError |
cookielib.CookieJar |
http.CookieJar |
urllib库是用于操作URL,爬取页面的python第三方库,同样的库还有requests、httplib2。
在Python2.X中,分urllib和urllib2,但在Python3.X中,都统一合并到urllib中。通过上表可以看到其中常见的变动,依据该变动可快速写出相应版本的python程序。
相对来说,Python3.X对中文的支持比Python2.X友好,所以该博客接下来通过Python3.X来介绍urllib库的一些常见用法。