0

Is it possible to continue a request session in selenium will all its cookies, i have seen many people doing it the other way arround but i have no clue how to do it proper the way i want.

    def open_selenium_session(self):
        # get or set cookies 
        driver = get_chromedriver(self.proxy, use_proxy=True, user_agent=True)
        driver.get("https://www.instagram.com")
        cookies = driver.get_cookies()
        for cookie in cookies:
            self.session.cookies.set(cookie['name'], cookie['value'])

1 Answers1

0

Incase you have stored the cookies previesly from an active session using pickle:

import pickle
pickle.dump( driver.get_cookies() , open("cookies.pkl","wb"))

You can always set them back as follows:

# loading the stored cookies
cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
    # adding the cookies to the session through webdriver instance
    driver.add_cookie(cookie)

Reference

You can find a couple of detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352