您可以使用以下方法轻松创建持久会话:
s = requests.Session()
之后,请继续执行您的请求:
s.post('https://localhost/login.py', login_data)#logged in! cookies saved for future requests.r2 = s.get('https://localhost/profile_data.json', ...)#cookies sent automatically!#do whatever, s will keep your cookies intact :)有关会话的更多信息,请访问:https : //requests.kennethreitz.org/en/master/user/advanced/#session-
objects



