Created
June 15, 2016 10:42
-
-
Save ladder1984/4b735639a97d58db4d5bae8fc0736163 to your computer and use it in GitHub Desktop.
url_add_params
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
import urlparse | |
def url_add_params(url, **params): | |
pr = urlparse.urlparse(url) | |
query = dict(urlparse.parse_qsl(pr.query)) | |
query.update(params) | |
prlist = list(pr) | |
prlist[4] = urllib.urlencode(query) | |
return urlparse.ParseResult(*prlist).geturl() | |
if __name__ == "__main__": | |
url = 'http://www.qq.com:88/?a=1212' | |
print url_add_params(url, aa=123, bb="bbs") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment