关于urllib.request.quote()函数
本帖最后由 fc5igm 于 2021-6-19 22:06 编辑[以下为引用]
URL 的编码与解码可以使用 urllib.request.quote() 与 urllib.request.unquote() 方法:
实例
import urllib.request
encode_url = urllib.request.quote("https://www.runoob.com/")# 编码
print(encode_url)
unencode_url = urllib.request.unquote(encode_url) # 解码
print(unencode_url)
输出结果为:
https%3A//www.runoob.com/
https://www.runoob.com/
[结束]
请问以上这段话所描述的quote函数,到底有什么用处?
谁能帮忙讲一讲大概什么情况下才会用到它么?
(由提问改为学习笔记) 本帖最后由 fc5igm 于 2021-6-19 22:04 编辑
import urllib.request
import urllib.parse
url = 'https://www.runoob.com/?s='# 菜鸟教程搜索页面
keyword = 'Python 教程'
key_code = urllib.request.quote(keyword)# 对请求进行编码
url_all = url+key_code
>>> url_all
'https://www.runoob.com/?s=Python%20%E6%95%99%E7%A8%8B'
>>> urllib.request.unquote(url_all)
'https://www.runoob.com/?s=Python 教程' 可以
页:
[1]