简体   繁体   English

在Python中发出请求之前如何获取Cookie

[英]How to get cookies before making request in Python

I am basically running my personal project,but i'm stuck in some point.I am trying to make a login request to hulu.com using Python's request module but the problem is hulu needs a cookie and a CSRF token.When I inspected the request with HTTP Debugger it shows me the action URL and some request headers.But the cookie and the CSRF token was already there.But how to can do that with request module? 我基本上是在运行我的个人项目,但是我有些卡住了。我正在尝试使用Python的request模块向hulu.com发出登录请求,但问题是hulu需要一个cookie和一个CSRF令牌。使用HTTP调试器发出请求,它向我显示了操作URL和一些request标头,但是cookie和CSRF令牌已经存在了,但是如何使用请求模块来做到这一点呢? I mean getting the cookies and the CSRF token before the post request? 我的意思是在发布请求之前获取cookie和CSRF令牌? Any ideas? 有任何想法吗? Thanks 谢谢

首先创建一个会话,然后使用GET并使用session.cookies.get_dict() ,它将返回一个dict,并且应该具有您需要的适当值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM