Created
November 13, 2019 02:40
-
-
Save adamghill/fd8e4693be989c4245d9b83a8ac1c136 to your computer and use it in GitHub Desktop.
Parse url for querystrings
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
""" | |
`furl` is really nice, but if it's only used for easily grabbing querstrings, you can use the `urlib.parse` module instead. | |
""" | |
url = "http://www.test.com?some_qs_here=asdf" | |
# Instead of this... | |
from furl import furl | |
parsed_url = furl(url) | |
some_qs_here = parsed_url.args["some_qs_here"] | |
# Just do this... | |
from urllib import parse | |
querystrings = dict(parse.parse_qs(parse.urlsplit(url).query)) | |
some_qs_here = querystrings["some_qs_here"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment