抓取response有转译如何解决 “http://”与“http%3A%2F%2F”
1、JS中提供转义字符串和解析字符串的方法
解析字符串(decodeURIComponent)
let url = 'http%3A%2F%2Fbaidu.com%2Flogin' url = decodeURIComponent(url) console.log(url)
// http://baidu.com/login
转义字符串(encodeURIComponent)
let url = 'http://baidu.com/login' url = encodeURIComponent(url) console.log(url)
2、Python的unquote方法
python2.7
中,使用urllib.unquote:
import urllib url = 'http%3A%2F%2Fbaidu.com%2Flogin'
a=urllib.unquote(urllib.unquote(url))
print a
python3+
中,使用urllib.parse.unquotefrom urllib.parse import unquote url = 'http%3A%2F%2Fbaidu.com%2Flogin' a = unquote(unquote(url))
print(a)
补充:
urlencode是一个函数,可将字符串以URL编码,用于编码处理。
![](https://img2022.cnblogs.com/blog/2225365/202206/2225365-20220617114224279-690697175.png)
在线转化网址
https://tool.chinaz.com/tools/urlencode.aspx