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?
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.