urllib.urlparse

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' )


urllib.parse. unquote_to_bytes ( string ) 将query中的查询值转换为一个URL编码的字符串,该字符串可以作为URL的query参数包括在
内,或者可以上传作为POST请求的一部分

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值