抓取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.unquote
from urllib.parse import unquote
url = 'http%3A%2F%2Fbaidu.com%2Flogin'
a = unquote(unquote(url))
print(a)

 补充:

urlencode是一个函数,可将字符串以URL编码,用于编码处理。
  
在线转化网址
https://tool.chinaz.com/tools/urlencode.aspx
 
posted @ 2022-12-30 15:13  AllIhave  阅读(393)  评论(0编辑  收藏  举报