search

Home  >  Q&A  >  body text

python - py3 需要将一段字符通过 unquote_plus 解码.但是 py2 和 py3 解码之后结果不同

PHP中文网PHP中文网2810 days ago556

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-04-18 09:37:37

    Is this so?

    >>> import urllib.parse as prs
    >>> prs.unquote_to_bytes(paragraph)
    b'BZh91AY&SY\x94:\xe2I\x00\x00!\x19\x80P\x81\x11\x00\xafg\x9e\xa0+\x00hE=M\xb5#\xd0\xd4\xd1\xe2\x8d\x06\xa9\xfa&S\xd4\xd3!\xa1\xeai7h\x9b\x9a+\xbf`"\xc5WX\xe1\xadL\x80\xe8V<\xc6\xa8\xdbH&32\x18\xa8x\x01\x08!\x8dS\x0b\xc8\xaf\x96KO\xca2\xb0\xf1\xbd\x1du\xa0\x86\x05\x92s\xb0\x92\xc4Bc\xf1w$S\x85\t\tC\xae$\x90'

    Replace +空格

    >>> import urllib.parse as prs
    >>> pg=paragraph.replace('+', ' ')
    >>> prs.unquote_to_bytes(pg)
    b'BZh91AY&SY\x94:\xe2I\x00\x00!\x19\x80P\x81\x11\x00\xafg\x9e\xa0 \x00hE=M\xb5#\xd0\xd4\xd1\xe2\x8d\x06\xa9\xfa&S\xd4\xd3!\xa1\xeai7h\x9b\x9a+\xbf`"\xc5WX\xe1\xadL\x80\xe8V<\xc6\xa8\xdbH&32\x18\xa8x\x01\x08!\x8dS\x0b\xc8\xaf\x96KO\xca2\xb0\xf1\xbd\x1du\xa0\x86\x05\x92s\xb0\x92\xc4Bc\xf1w$S\x85\t\tC\xae$\x90'

    reply
    0
  • Cancelreply