python2 、python3 urllib 模块一些特别的对应关系

python2 "from urllib import quote" 对应 python3 "from urllib import parse"

 

urillb2在python3中的变化。

在Pytho2.x中使用import urllib2——-对应的,在Python3.x中会使用import urllib.request,urllib.error。
在Pytho2.x中使用import urllib——-对应的,在Python3.x中会使用import urllib.request,urllib.error,urllib.parse
在Pytho2.x中使用import urlparse——-对应的,在Python3.x中会使用import urllib.parse。
在Pytho2.x中使用import urlopen——-对应的,在Python3.x中会使用import urllib.request.urlopen。
在Pytho2.x中使用import urlencode——-对应的,在Python3.x中会使用import urllib.parse.urlencode。
在Pytho2.x中使用import urllib.quote——-对应的,在Python3.x中会使用import urllib.request.quote。
在Pytho2.x中使用cookielib.CookieJar——-对应的,在Python3.x中会使用http.CookieJar。
在Pytho2.x中使用urllib2.Request——-对应的,在Python3.x中会使用urllib.request.Request。

需求:  将python3 代码中urllib 模块对应到python2   记录如下:

python2              ->           python3  

from urllib import quote     ->       from urllib import parse

urllib.quote           ->       parse.quote

------------------------------------------------------------------------------------------------------------------------------

import urlparse      ->                   from urllib.parse import urlparse / import  urllib.parse

urlparse.urlparse      ->       urlparse

----------------------------------------------------------------------------------------------------------------------------------------

import urllib2        ->        import urllib.request

urllib2.Request                    ->                             urllib.request.Request

 

posted @ 2019-11-25 18:34  rockstics  阅读(1082)  评论(0编辑  收藏  举报