zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    jquery 父、子页面之间页面元素的获取,方法的调用
    读excle
    dataTable写入数据库(大数据写入)
    经典类和新式类的区别
    重写父类方法
    封装redis
    继承
    私有方法
    优化MyDb

  • 原文地址:https://www.cnblogs.com/rockstics/p/11929505.html
Copyright © 2011-2022 走看看