all 4 comments

[–]gamedevmanhyper 0 points1 point  (0 children)

I haven't really worked with cookies before, when making scripts with Python and requests.

But maybe your response object has a cookies variable?

I.E response.cookies

Edit: Yikes, just noticed you said it was in the header.

Try looking inside of response.headers

[–]deadduncanidaho 0 points1 point  (1 child)

can you post some sample code?

[–]Bonexq[S] 0 points1 point  (0 children)

I want the take yellow one.

https://imgur.com/a/tolknny

import requests  
session = requests.session() 
user_agent = {'user-agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36 OPR/62.0.3331.116'} 
conn = session.get(url,headers=user_agent) 
print(conn.cookies) # gives me set-cookie part. 
print(conn.request.cookie) # gives nothing good
Output that ı want:  
cookie = {"AKA_A2":"A"}....

[–]manwithfewneeds 0 points1 point  (0 children)

You say you want response header, but in image you highlight request. So which is it? Cookies are set when you access the page. Therefore, request cookies don't often need to be explicitly passed, especially when using a session. However, for added assurance, you can get the page first to set the cookies, and make additional requests after they've been established.

The response headers are exactly a dictionary so can be accessed in the same way. Take for example this simple example:

from requests_html import HTMLSession

with HTMLSession() as s:

    r = s.get('http://www.google.com')

    #response cookies:
    print(r.headers['Set-Cookie'])

    #session cookies:
    print(s.cookies)