python-requests是否有任何回调方法? [英] Does python-requests have any callback method?

查看:308
本文介绍了python-requests是否有任何回调方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我想要的.

s = Session()    

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

def do_this(self, response):
    print response.url

推荐答案

您可以使用事件挂钩:

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


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

s.get(...)

此处的文档: https://requests.kennethreitz.org /en/master/user/advanced/#event-hooks

这篇关于python-requests是否有任何回调方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆