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
Post a Comment