获取url参数 urlparse 和 parse_qs
from urllib import parse
url = 'https://docs.python.org/3.5/search.html?q=parse&check_keywords=yes&area=default'
parseResult = parse.urlparse(url)
print(parseResult)
param_dict = parse.parse_qs(parseResult.query)
print(param_dict)
q = param_dict['q'][0]
print(q)
param_dict = parse.parse_qs('proxy=183.222.102.178:8080&task=XXXXX|5-3+2')
print(param_dict)
ParseResult(scheme='https', netloc='docs.python.org', path='/3.5/search.html', params='', query='q=parse&check_keywords=yes&area=default', fragment='')
{'q': ['parse'], 'check_keywords': ['yes'], 'area': ['default']}
parse
{'proxy': ['183.222.102.178:8080'], 'task': ['XXXXX|5-3 2']}
urlencode json 解析成 url参数
from urllib import parse
query = {
'name': 'walker',
'age': 99,
}
str = parse.urlencode(query)
print(str)
对url参数进行编码 quote/quote_plus
from urllib import parse
str = parse.quote('a&b/c')
print(str)
from urllib import parse
str = parse.quote_plus('a&b/c')
print(str)
对url参数进行解码 unquote/unquote_plus
from urllib import parse
str = parse.unquote('a%26b%2Fc1+2')
print(str)
str = parse.unquote_plus('a%26b/c1+2')
print(str)