python - 无法使用 Python 请求保存来自网站的 cookie?

标签 python python-3.x cookies python-requests

链接:http://www.ibnlive.com/videos/world/

通过使用网络浏览器,当页面加载时,我可以轻松地看到以下 cookie,如下所示:

enter image description here

但是如果我尝试使用 python 请求加载相同的 cookie,它会显示为空字典:

import requests
s = requests.session()
connection = s.get('http://www.ibnlive.com/videos/world/')
print(s.cookies) # produces an empty dictionary

我的问题是如何使用 python 脚本获取这些 cookie?

最佳答案

因为 cookie 不是由 http://www.ibnlive.com/videos/world/ 设置的,而是由页面正在加载的其他一些资源设置的。尝试查看该 url 的 header ,您不会看到任何 Set-Cookie header 。

关于python - 无法使用 Python 请求保存来自网站的 cookie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34329061/

相关文章:

python - 如何在 PyTorch 中保存经过训练的模型?

python - 使用 xml.etree.ElementTree 解析 XML 文件时出现问题

python - 为什么 request.method 没有被调用?

python - 谷歌的 protorpc 坏了(元类错误)

python - 如何访问 conftest.py 中的 json 文件(测试数据如 config.json)

python - 如何使 QTableWidget 中的单元格只读?

python-3.x - 根据其他列值对多个数据框列进行分组

python - 使用 Mechanize 登录

Codeigniter - cookie 在 Internet Explorer 8 中不起作用

django - 当我在 Django 项目中使用时,为什么 HttpResponseRedirect.set_cookie 不起作用?