0

I want to reuse a whatsapp web session via Python 3 and Selenium on Chromedriver.

For which I need to grab the localstorage of an existing session and set it to the new browser instance before opening whatsapp web again.

I do so, on a logged in session:

cacho="";
for (var i = 0; i < localStorage.length; i++){
cacho+="localStorage.setItem('"+localStorage.key(i)+"', '"+localStorage.getItem(localStorage.key(i))+"');"
}
alert(cacho)

With driver.execute_script(), and I get the working localstorage data.

I copy the whole thing (a few javascript lines) and then, when opening a new browser instance, I do:

driver.execute_script(the_whole_thing)
driver.get(url)

But the session is not alive.

What am I missing here?

Álvaro N. Franz
  • 1,188
  • 3
  • 17
  • 39

1 Answers1

0

this is how you can reuse a whatsapp web session by storing cookies.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--user-data-dir=chrome-data")
driver = webdriver.Chrome('chromedriver.exe',options=chrome_options)
driver.get('https://web.whatsapp.com')
time.sleep(30)