美文网首页
python模块 furl 使得操纵URL简单化,去除网址中参数

python模块 furl 使得操纵URL简单化,去除网址中参数

作者: Pala风 | 来源:发表于2018-08-09 18:54 被阅读37次

python模块 furl 使得操纵URL简单化,去除网址中参数

安装:

pip install furl

git网址:

https://github.com/gruns/furl

使用教程:
修改和添加参数

>>> from furl import furl
>>> f = furl('http://www.google.com/?one=1&two=2')
>>> f.args['three'] = '3'
>>> del f.args['one']
>>> f.url
'http://www.google.com/?two=2&three=3'

使用furl的内联修改方法。

>>> furl('http://www.google.com/?one=1').add({'two':'2'}).url
'http://www.google.com/?one=1&two=2'

>>> furl('http://www.google.com/?one=1&two=2').set({'three':'3'}).url
'http://www.google.com/?three=3'

>>> furl('http://www.google.com/?one=1&two=2').remove(['one']).url
'http://www.google.com/?two=2'

编码处理

>>> f = furl('http://www.google.com/')
>>> f.path = 'some encoding here'
>>> f.args['and some encoding'] = 'here, too'
>>> f.url
'http://www.google.com/some%20encoding%20here?and+some+encoding=here,+too'
>>> f.set(host=u'ドメイン.テスト', path=u'джк', query=u'☃=☺')
>>> f.url
'http://xn--eckwd4c7c.xn--zckzah/%D0%B4%D0%B6%D0%BA?%E2%98%83=%E2%98%BA'

url添加查询参数和路径

>>> f = furl('http://www.google.com/')
>>> f.fragment.path.segments = ['two', 'directories']
>>> f.fragment.args = {'one': 'argument'}
>>> f.url
'http://www.google.com/#two/directories?one=argument'

相关文章

网友评论

      本文标题:python模块 furl 使得操纵URL简单化,去除网址中参数

      本文链接:https://www.haomeiwen.com/subject/tvicbftx.html