[Python] Python Selenium - Can't retrieve cookies with driver.get_cookies() in private mode in...

Discussão em 'Python' iniciado por Stack, Novembro 23, 2025.

  1. Stack

    Stack Membro Participativo

    I want to get specific cookies that are only obtainable when in private mode. Chrome cannot be used.

    I initially used the following code:

    from selenium import webdriver
    from selenium.webdriver.firefox.options import Options

    options = Options()
    options.set_preference("browser.privatebrowsing.autostart", True)
    driver = webdriver.Firefox(options=options)

    driver.get("https://www.websitewithcookies.com")
    print(driver.get_cookies())


    But it printed out an empty list. I also tried setting this option.

    options.set_preference("privacy.firstparty.isolate", True)


    When using this option, the website has the cookies I need but it also prints out an empty list.

    I could retrieve the cookies using a Javascript code with driver.execute_script("return document.cookie;"), but it doesn't print every cookie (e.g. cookies that are HttpOnly aren't shown).

    I looked at this stack overflow post but it didn't have any answers.

    Continue reading...

Compartilhe esta Página