title: Python-Requests, extract url parameters from a string
body: <p>I am using this awesome library called <a href="http://docs.python-requests.org/en/latest" rel="noreferrer"><code>requests</code></a> to maintain python 2 &amp; 3 compatibility and simplify my application requests management.</p>
  
  <p>I have a case where I need to parse a url and replace one of it's parameter. E.g:</p>
  
  <pre><code>http://example.com?param1=a&amp;token=TOKEN_TO_REPLACE&amp;param2=c
  </code></pre>
  
  <p>And I want to get this:</p>
  
  <pre><code>http://example.com?param1=a&amp;token=NEW_TOKEN&amp;param2=c
  </code></pre>
  
  <p>With the <code>urllib</code> I can achieve it this way:</p>
  
  <pre><code>from urllib.parse import urlparse
  from urllib.parse import parse_qs
  from urllib.parse import urlencode
  
  url = 'http://example.com?param1=a&amp;token=TOKEN_TO_REPLACE&amp;param2=c'
  
  o = urlparse(url)
  query = parse_qs(o.query)
  if query.get('token'):
      query['token'] = ['NEW_TOKEN', ]
      new_query = urlencode(query, doseq=True)
      url.split('?')[0] + '?' + new_query
  
  &gt;&gt;&gt; http://example.com?param2=c&amp;param1=a&amp;token=NEW_TOKEN
  </code></pre>
  
  <p>How can you achieve the same using the <code>requests</code> library?</p>