简体   繁体   中英

Python get cookies on request

I've seen many topics asking to get cookies after a request has been made but I want the cookies Python sends out to a website. I have a site ( site.com ) where if you go to they give you an Authorization cookie. This is not in the response cookies but it's in the request cookies on Firefox Network activity. I'm wondering, is it posible to get the cookies sent with a request to a site?

I've tried:

import requests

session = requests.Session()
session.get("site.com")
print(session.cookies.get_dict())

But that didn't give me the request cookies

I do this and it does work.

>>> import requests
>>> session = requests.Session()
>>> print(session.cookies.get_dict())
{}
>>> response = session.get('http://google.com')
>>> print(session.cookies.get_dict())
{'PREF': 'ID=5514c728c9215a9a:FF=0:TM=1406958091:LM=1406958091:S=KfAG0U9jYhrB0XNf', 'NID': '67=TVMYiq2wLMNvJi5SiaONeIQVNqxSc2RAwVrCnuYgTQYAHIZAGESHHPL0xsyM9EMpluLDQgaj3db_V37NjvshV-eoQdA8u43M8UwHMqZdL-S2gjho8j0-Fe1XuH5wYr9v'}

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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