python3中的urllib网页的编码(urlencode)、解码(unquote),以访问百度为例,在接口输入字符的时候为中文,但是计算机需要编码才能识别。

from urllib import request
from urllib import parse     #导入编码  解码包
#百度url     https://www.baidu.com/s?wd=关晓彤      网页输入
#百度url     https://www.baidu.com/s?wd=%E5%85%B3%E6%99%93%E5%BD%A4    实际输出可以辨别的代码
word={"wd":"关晓彤"}
print(parse.urlencode(word))    # urlencode  中文  编码转化为  url识别的字符
#print(type(parse.urlencode(word)))
print(parse.unquote(parse.urlencode(word)))  #  unquote  解码为中文字符

运行结果如下:

wd=%E5%85%B3%E6%99%93%E5%BD%A4
wd=关晓彤

Process finished with exit code 0

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-31
  • 2021-10-30
  • 2022-12-23
  • 2021-05-26
  • 2021-06-26
  • 2021-08-20
猜你喜欢
  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
  • 2021-11-29
  • 2022-12-23
  • 2021-10-20
相关资源
相似解决方案