转自:微点阅读 https://www.weidianyuedu.com
quote()
传入参数类型:字符串
功能:将单个字符串编码转化为 %xx 的形式
导入:from urllib.parse import quote
Ps:url多个字符串编码用urlenocde()函数
例子1:url标准符号:数字字母
from urllib.parse import quoteKEYWORD = "ipad"url = "https://s.taobao.com/search?q=" + quote(KEYWORD)print(url)# 运行结果:https://s.taobao.com/search?q=ipadKEYWORD = "3346778"url = "https://s.taobao.com/search?q=" + quote(KEYWORD)print(url)# 运行结果:https://s.taobao.com/search?q=3346778
例子2:特殊符号:汉字、&、=等特殊符号编码为%xx
from urllib.parse import quote"""特殊符号:汉字、&、=等特殊符号编码为%xx """KEYWORD = "苹果"url = "https://s.taobao.com/search?q=" + quote(KEYWORD)print(url)# 运行结果:https://s.taobao.com/search?q=%E8%8B%B9%E6%9E%9CKEYWORD = "="url = "https://s.taobao.com/search?q=" + quote(KEYWORD)print(url)# 运行结果:https://s.taobao.com/search?q=%3D