urllib.parse.urlparse(urlstring, scheme='', allow_fragments=True)
scheme:设置默认值
allow_fragments:是否允许fragment
>>> from urllib.parse import urlparse >>> o = urlparse('http://www.cwi.nl:80/%7Eguido/Python.html') >>> o ParseResult(scheme='http', netloc='www.cwi.nl:80', path='/%7Eguido/Python.html', params='', query='', fragment='') >>> o.scheme 'http' >>> o.port 80 >>> o.geturl() 'http://www.cwi.nl:80/%7Eguido/Python.html'urlparse recognizes a netloc only if it is properly introduced by ‘//’. Otherwise the input is presumed to be a relative URL and thus to start with a path component.
urllib.parse. parse_qs ( qs, keep_blank_values=False, strict_parsing=False, encoding='utf-8', errors='replace' )解析一个查询字符串,返回一个dict对象。
keep_blank_values:是否保留空格
strict_parsing:如果为False,解析时出错将忽略,为True,解析出错将抛出一个ValueError异常。
使用urllib.parse.urlencode() 函数,可将这样的字典转成查询字符串
urllib.parse. parse_qsl ( qs, keep_blank_values=False, strict_parsing=False, encoding='utf-8', errors='replace' )返回一个列表
urllib.parse. urlunparse ( parts )由urlparse返回的tuple构造一个URL
urllib.parse. urlsplit ( urlstring, scheme='', allow_fragments=True )This is similar to urlparse(), but does not split the params from the URL.
This function returns a 5-tuple
urllib.parse. urlunsplit ( parts )Combine the elements of a tuple as returned by urlsplit() into a complete URL as a string
urllib.parse. urljoin ( base, url, allow_fragments=True )如果URL里包含fragment identifier,则返回一个不含fragment identifier的url和一个fragment identifier的列表。如果url本来就不含fragment identifier,则返回原url
urllib.parse. quote ( string, safe='/', encoding=None, errors=None )编码URL字符串。safe指定不需要编码的 ASCII字符。
encoding,设置如何处理无法编码的非ASCII 字符
urllib.parse. quote_plus ( string, safe='', encoding=None, errors=None )与quote()类似,但其将空格替换为‘+’,原‘+’将被转义。其safe 默认不包含‘/’
urllib.parse. quote_from_bytes ( bytes, safe='/' )
urllib.parse. unquote ( string, encoding='utf-8', errors='replace' )
urllib.parse. unquote_plus ( string, encoding='utf-8', errors='replace' )
内,或者可以上传作为POST请求的一部分