urllib.parse quote/unquate/urlencode

  1. quote: url encoding function, will be converted to Chinese% xxxx
    # _*_ coding::utf_8 _*_
    import urllib.request
    import urllib.parse
    url='http://baidu.com/index.html?name=杨洪&pwd=123456'
    ret=urllib.parse.quote(url)
    ret1=urllib.parse.unquote(ret)
    print(ret)
    print(ret1)
    
    
    ##输出结果:
    http%3A//baidu.com/index.html%3Fname%3D%E6%9D%A8%E6%B4%AA%E8%BE%89%26pwd%3D123456
    
    
    http://baidu.com/index.html?name=杨洪&pwd=123456

     

  2. unquote: url decoding function, the specified character conversion% XXX
  3. urllencode: Given a dictionary, the dictionary is QUERY_STRING splicing, and achieves coding function
    # _*_ coding::utf_8 _*_
    import urllib.parse
    url='http://baidu.com/index.html'
    data={
        'name':'goudan',
        'sex':'',
         'age':'18'
    }
    query_string=urllib.parse.urlencode(data)
    print(query_string)
    url=url+"?"
    operating results
    ####The QUERY_STRING+
    print(url)
    name = goudan & Sex =% E5% A5% B3 & Age = 18 
    HTTP: // baidu.com/index.html?name=goudan&sex=%E5%A5%B3&age=18 
    # stitching for the url

     

Guess you like

Origin www.cnblogs.com/ybl20000418/p/11564822.html