作为对象或功能样式进行url解析和编辑。

urledit的Python项目详细描述


作为对象或功能样式进行url解析和编辑。

>>> from urledit import urledit
>>> url = 'forum/showthread.php?s=12345&p=728386#post728386'

功能样式

>>> urledit(url)(scheme='http')(netloc='host.com')(fragment=''
... ).param(s=None).param(a=1).param(b=['x', 'y', 'z']).join()
'http://host.com/forum/showthread.php?p=728386&a=1&b=x&b=y&b=z'

>>> urledit(url, scheme='http', netloc='host.com', fragment=''
... ).param(('s', None), ('a', 1), b=['x', 'y', 'z']).join()
'http://host.com/forum/showthread.php?p=728386&a=1&b=x&b=y&b=z'

对象样式

>>> u = urledit(url)
>>> u.scheme, u.netloc, u.path, u.qs, u.fragment
('', '', 'forum/showthread.php', 's=12345&p=728386', 'post728386')
>>> u.scheme, u.netloc, u.fragment = 'http', 'host.com', ''
>>> u.join()
'http://host.com/forum/showthread.php?s=12345&p=728386'

使用查询字符串:

>>> u.query == {'p': '728386', 's': '12345'}
True
>>> del u.query['s']
>>> u.join()
'http://host.com/forum/showthread.php?p=728386'
>>> u.query['a'] = 1
>>> u.query['b'] = ['x', 'y', 'z']
>>> u.join()
'http://host.com/forum/showthread.php?p=728386&a=1&b=x&b=y&b=z'

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java向嵌入式Jetty添加多个端点   java如何在JAXWS处理程序中区分请求和响应?   使用Scenebuilder for JAVAFx的登录应用程序的java MVC体系结构   java对话框将不显示   Windows 7上的Java系统变量   java删除动态添加的面板   java将Javadoc嵌入到HTML网站中   带有URL编码数据的java Spring RestTemplate POST请求   java JAXR只运行一次函数   HttpClient缺少java依赖项   java深层反射比较   基于javarmi和CORBA的分布式计算   如何使用当前数据库时间从Java更新MongoDB?   java通过光标保存数据调试时显示错误数据