<p>您可以分别从每个cookie中提取信息:</p>
<pre><code>import requests
r = requests.post('http://www.about.com')
for cookie in r.cookies:
print(cookie.__dict__)
print(cookie.secure)
</code></pre>
<p>这是因为<code>r.cookies</code>是<code>RequestsCookieJar</code>的一个实例,它扩展自<code>CookieJar</code>(Python 2:<code>cookielib.CookieJar</code>,Python 3:<code>http.cookiejar.CookieJar</code>)。一个<code>CookieJar</code>有<code>Cookie</code>个对象。</p>
<p><strong>参考资料:</strong></p>
<ul>
<li>库基里布:<a href="https://docs.python.org/2.7/library/cookielib.html" rel="nofollow noreferrer">https://docs.python.org/2.7/library/cookielib.html</a></li>
<li>cookielib.Cookie.secure:<a href="https://docs.python.org/2.7/library/cookielib.html#cookielib.Cookie.secure" rel="nofollow noreferrer">https://docs.python.org/2.7/library/cookielib.html#cookielib.Cookie.secure</a></li>
<li><a href="https://stackoverflow.com/a/27523891/295246">https://stackoverflow.com/a/27523891/295246</a></li>
</ul>
<p><strong>更新:</strong>
我还没有找到从<code>Cookie</code>对象检索<code>httponly</code>值的方法。在Python 3中,可以通过字典定义<code>Mosel</code>对象,它认为<code>httponly</code>是cookie(<a href="https://docs.python.org/3/library/http.cookies.html" rel="nofollow noreferrer">https://docs.python.org/3/library/http.cookies.html</a>)的标准属性,但在定义规范RFC2109(<a href="https://www.ietf.org/rfc/rfc2109.txt" rel="nofollow noreferrer">https://www.ietf.org/rfc/rfc2109.txt</a>)中找不到对<code>httponly</code>的任何引用。</p>
<p>也就是说,如果<code>httponly</code>实际上是一个非标准属性,那么您可以使用以下命令检查cookie是否具有它:
<code>cookie.has_nonstandard_attr('httponly')</code></p>