0

I'm using python and selenium to browse a website, once logged in I would like to transfer the session (exporting cookies) from the selenium browser to a python requests session, but I noticed that there is a cookie called "session-token " which is not transferred, I also noticed that this cookie is marked as:

  • HostOnly
  • Secure
  • HttpOnly

I've already read this question, using Postman's Interceptor bridge extension and synchronizing cookies, I noticed that the "session-token" cookie is exported to the desktop program, how is this possible? Is there any way to read the value of this cookie?

I tried logging in directly using requests but the cookie is not being set. I also tried to print the cookies using the console, this is the code:

var theCookies = document.cookie.split(';');
for (var i = 0 ; i <= theCookies.length; i++) {
   console.log(theCookies[0] );
}

but the cookie is not printed.

2 Answers2

1

The "session-token" cookie you mentioned is likely being set as a secure and HttpOnly cookie.

see this link: How can I read httponly and secure cookies in the browser with Javascript?.

if you want you can extract cookies manually:

driver = webdriver.Chrome()
# Do necessary actions to log in and navigate to the desired page
# ...

# Get cookies from Selenium
cookies = driver.get_cookies()
0

If you are using selenium there's a method to get all of the cookies

driver = webdriver.Chrome()

# this will return all the cookies context
cookies = driver.get_cookies()

if you tend to using Python's requests, you can achieve that with called this method

session = requests.Session()
resp = session.get("your-target-url")

# this will return as dictionary object
print(resp.cookies.get_dict())