Skip to content

Instantly share code, notes, and snippets.

@devnullone
Last active November 30, 2022 09:11
Show Gist options
  • Save devnullone/6aa157b36a4163ee1ce79a6adde1b9c7 to your computer and use it in GitHub Desktop.
Save devnullone/6aa157b36a4163ee1ce79a6adde1b9c7 to your computer and use it in GitHub Desktop.
import urllib.parse
url = "http://stackoverflow.com/search?q=question"
params = {'lang':'en','tag':'python'}
url_parts = urllib.parse.urlparse(url)
query = dict(urllib.parse.parse_qsl(url_parts.query))
query.update(params)
new_url = url_parts._replace(query=urllib.parse.urlencode(query)).geturl()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment