4

Here is what I am looking for.

s = Session()    

s.get(url, callback=self.do_this)

def do_this(self, response):
    print response.url
Talha Ashraf
  • 1,201
  • 2
  • 14
  • 19

2 Answers2

6

You can use event hooks:

def display_url(r, **kwargs):
    print(r.url)


s = Session()
s.hooks['response'].append(display_url)

s.get(...)

Documentation here: https://requests.kennethreitz.org/en/master/user/advanced/#event-hooks

Kyle James Walker
  • 1,238
  • 14
  • 16
2

Use grequests to have asynchronous requests with gevent. There is a callback keyword argument to .get().

mguijarr
  • 7,641
  • 6
  • 45
  • 72
  • there is no `callback` keyword to `.get()` – Eliav Louski Jul 19 '22 at 12:48
  • @EliavLouski `get` is an `AsyncRequest` , it takes a `callback` keyword argument - so you can do `from grequests import get ; get(url, callback=func)` it is even written in the `AsyncRequest` docstring... This is still valid in latest 0.6.0 – mguijarr Jul 20 '22 at 17:49