python - scrapy - 从响应/请求 header 获取cookie

标签 python session cookies scrapy

我尝试使用这行代码从请求中获取 cookie,但得到了 [] 空结果

response.headers.getList('Set-Cookie')

还有这个

response.request.headers.get('Cookie')

当我open_in_browser响应时,我检查“网络”选项卡并看到cookie存在(参见下图)

enter image description here

enter image description here

有什么想法吗?谢谢

最佳答案

response.headers.getlist("Set-Cookie") 对我有用(Scrapy 1.4.0)

但首先,在 shell 中检查您是否确实收到了此 cookie:

scrapy shell
fetch('your_url')
response.headers.getlist("Set-Cookie")

关于python - scrapy - 从响应/请求 header 获取cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46543143/

相关文章:

python - 如何将 AWS-Fargate 用作 python 脚本

python - super 计算机: Dead simple example of a program to run in supercomputer

PHP 将变量传递到下一页

ruby-on-rails - 在 Rails cookie 中存储/检索值

Python - 找到相似的颜色,最好的方法

python - Bash别名自动检测任意命名的文件序列?

node.js - sails js 中的当前 session ID

asp.net - 将 session 信息存储在 ASP.Net Cookie 或 session 状态中?

wordpress - Set-Cookie 阻止我登录 WordPress

jquery - 为什么 JSON.stringify() 不将数据传递给 $.cookie()