python requests: easy way to replace http get request argument? -


i have http request so:

url = 'www.somedomain.com/content?var=whatever&pageno=1' r = requests.get(url) 

i'd replace pageno=1 pageno=2, requests humans, couldn't figure out how without parsing query pyhton dictionary using urlparse, change corresponding value, urllib.urlencode new query.

notice

i know can re.sub() , solve problem in 2 or 3 lines, think there must 'pythonic way'.

i've been using scrapy in past few months , got nice request.replace method this, think i'm gonna suggest feature requests.

you can utilize params argument of get() method. functionality described in quick start

>>> payload = {'var': 'whatever', 'pageno': '1'} >>> r = requests.get("http://www.somedomain.com/content", params=payload) >>> print(r.url) http://www.somedomain.com/content?var=whatever&pageno=1 

using method of passing parameters, can manipulate payload dictionary prior calling .get()


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -