quote()
- 传入参数类型:字符串
- 功能:将单个字符串编码转化为 %xx 的形式
- 导入:from urllib.parse import quote
- Ps:url多个字符串编码用urlenocde()函数
例子1:url标准符号:数字字母
from urllib.parse import quote
KEYWORD = 'ipad'
url = 'https://s.taobao.com/search?q=' + quote(KEYWORD)
print(url)
KEYWORD = '3346778'
url = 'https://s.taobao.com/search?q=' + quote(KEYWORD)
print(url)
例子2:特殊符号:汉字、&、=等特殊符号编码为%xx
from urllib.parse import quote
"""特殊符号:汉字、&、=等特殊符号编码为%xx """
KEYWORD = '苹果'
url = 'https://s.taobao.com/search?q=' + quote(KEYWORD)
print(url)
KEYWORD = '='
url = 'https://s.taobao.com/search?q=' + quote(KEYWORD)
print(url)
例子3:以上两例子默认utf8编码,如果用gb2312编码,则需指定
from urllib.parse import quote
text = quote("药品互联网信息服务", encoding="gb2312")
print(text)