Python请求 - 保存cookie以供以后使用url

Pyt*_*cks 5 python python-2.7 python-requests

我一直在尝试获取一个cookie并将其发布到以后在程序中使用的URL中,但我似乎无法使cookie参数起作用.

现在我有

response = requests.get("url")
Run Code Online (Sandbox Code Playgroud)

但是我究竟如何从此网址中检索Cookie并将其发布到新网址(相同的Cookie).请求中的教程在这个主题上有点模糊,并提供了我无法测试的示例.希望有人可以帮助进一步的例子.

这是python 2.7 btw.

Mar*_*ers 15

您想要使用会话:

s = requests.session()

response = s.get('url')
Run Code Online (Sandbox Code Playgroud)

您可以像requests模块一样使用会话(它具有相同的方法),但它会为您保留cookie并在将来的请求中发送它们.