python对url进行解码和编码

from urllib import parse


if __name__ == '__main__':

    str_ = '守护最好的鲲鲲'
    
    # url编码
    str_encode = parse.quote(str_)
    print(str_encode)    # %E5%AE%88%E6%8A%A4%E6%9C%80%E5%A5%BD%E7%9A%84%E9%B2%B2%E9%B2%B2
    
    # url解码
    str_decode = parse.unquote(str_encode)
    print(str_decode)    # 守护最好的鲲鲲   

PS:url多次编码之后再多次解码也可以还原

你可能感兴趣的:(Python,python日常开发工具包,python)