Skip to content

Instantly share code, notes, and snippets.

@xiazhibin
Created February 23, 2018 12:34
Show Gist options
  • Select an option

  • Save xiazhibin/e523f1b3eeddbc2643a280db8812dc2b to your computer and use it in GitHub Desktop.

Select an option

Save xiazhibin/e523f1b3eeddbc2643a280db8812dc2b to your computer and use it in GitHub Desktop.
解构URL
from urllib import urlencode
from urlparse import urlparse, urlunparse, parse_qsl
url = 'https://www.baidu.com?fuxk=true&m=1'
url_parts = list(urlparse(url))
query = dict(parse_qsl(url_parts[4]))
query.update({'nimabi': 1111})
url_parts[4] = urlencode(query)
print urlunparse(url_parts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment