How can I decode python-requests URL?
Question: I know if I want to send an HTTP request, I can form it as a dictionary before
sending it:

    
    
    payload = dict(
        username="something",
        password="something_else"
    )
    
    r = requests.get('http://example.com', params=payload)
    

Does it do the opposite as well? If my request happens to redirect me to
another URL, I can see where I was redirected with:

    
    
    print r.url
    

But if that URL happens to be something like:

    
    
    http://example.com/somepage.htm?varone=test&vartwo=3451&varthree=something
    

and I happen to want to pull out the vartwo from that URL (the string 3451),
does the requests module provide any easy way to do this just by specifying
that I want the value of "vartwo"? Another dictionary, or mapping object of
some sort perhaps? Or is my only option to use urllib.unquote to decode the
url, and parse it as a string?


Answer: Use [urlparse module](https://docs.python.org/2/library/urlparse.html) (Python
2.x; in Python 3.x, it was renamed to
[urllib.parse](https://docs.python.org/3/library/urllib.parse.html)).

    
    
    from urlparse import urlparse
    
    url = 'http://www.gurlge.com:80/path/file.html;params?a=1#fragment'
    o = urlparse(url)
    
    print o.params
    

