from urllib.parse import urlparse, urlunparse
def frag2param(url):
res = urlparse(url)
return urlunparse(res[0:4] + ("&".join([val for val in res[4:] if val]),
None))
frag2param("http://test.foo/cosi/page;code?day=0&night=2#param=1")
'http://test.foo/cosi/page;code?day=0&night=2¶m=1'
frag2param("http://test.foo/cosi/page;code#param=1")
'http://test.foo/cosi/page;code?param=1'
frag2param("http://test.foo/cosi/page;code?day=0&night=2")
'http://test.foo/cosi/page;code?day=0&night=2'
frag2param("http://test.foo/cosi/page")
'http://test.foo/cosi/page'
_______________________________________________ Python mailing list [email protected] http://www.py.cz/mailman/listinfo/python Visit: http://www.py.cz
