Retrieving cookies in Python can be done by the use of the Requests library. Requests library is one of the integral part of Python for making HTTP requests to a specified URL. The below codes show different approaches to do show:
1. By requesting a session:
# import the requests library import requests # initialize a session session = requests.Session() # send a get request to the server # print the response dictionary print(session.cookies.get_dict()) |
Output:
{‘1P_JAR’: ‘2020-04-30-07’, ‘NID’: ‘203=GIlzlNytcSGjMtV-ML49xgKQax4NACMgFZi56sbQ3tSd9uDqL7EWZ6KC_gUqPsKkk-XsDIlca8ElKqhjsHGgWrPRwbbPBFXxcGL_G5Jd0gzdQYhCo-QALsZm4zItqIeImlBBTp_TDOgRQIW0d2hSNerxmQkljluhIA3QGLgNLnM’}
2.By requesting cookies list from the server:
import requests for c in r.cookies: print(c.name +"==>>", c.value) |
Output:
1P_JAR==>> 2020-04-30-07
NID==>> 203=YvFCKkIeHS4SvpTVv8jw6MIGEU54IlN8V_1aQZrXmOU7Zdj74qZdW69E3A38KSP-GrE5xLmR40ozrHTFxkXm4-iaTm4DbhU4cwmvOWHEs1OZELI8H8KQLmBLCxccxCuHT07QQ2mqc-ppBYXhcHtOC7idVc9RWD2kmNPDMR-YMl4
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Retrieving And Updating Data Contained in Shelve in Python
- Python | setting and retrieving values of Tkinter variable
- Python IMDbPY – Retrieving person using person ID
- Python IMDbPY – Retrieving company using company ID
- Python IMDbPY - Retrieving movie using movie ID
- Python IMDbPY – Retrieving art department cast from the movie object
- Python IMDbPY - Retrieving actor from the movie details
- Python IMDbPY - Retrieving role played by actor from the movie details
- Retrieving File Data From HDFS using Python Snakebite
- response.cookies - Python requests
- Adding and Deleting Cookies in Selenium Python
- PyQt5 - Retrieving caption of Check Box
- PyQt5 Scrollable Label - Retrieving tooltip text
- PyQt5 QSpinBox - Retrieving Description
- Retrieving HTML From data using Flask
- ES6 | Cookies
- Important differences between Python 2.x and Python 3.x with examples
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Sort Python Dictionaries by Key or Value
- Python | Merge Python key values to list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

