在Python 3.6中解码%xx

时间:2018-09-05 15:09:29

标签: python python-3.x decode

我有

%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%62%65%6e%2e%61%6e%67%65%72%40%6b%6e%6f%62%62%65%2e%63%6f%6d%22%20%72%65%6c%3d%22%6e%6f%69%6e%64%65%78%2c%20%6e%6f%66%6f%6c%6c%6f%77%22%3e%62%65%6e%2e%61%6e%67%65%72%40%6b%6e%6f%62%62%65%2e%63%6f%6d%3c%2f%61%3e%27%29%3b

它来自我抓取的JavaScript标签。

不幸的是,Javascript unescape() vs. Python urllib.unquote()中的所有解决方案似乎都无法在Python 3中工作。

1 个答案:

答案 0 :(得分:4)

unquote()已移至Python 3中的urllib.parse包中。

>>> from urllib.parse import unquote
>>> unquote('%64%6f%63%75%6d%65%6e%74%2e')
'document.'