问题
Scenario:
I am working an an auto whatsapp responder using whatsapp web.
I log in via chromedriver on selenium with python 3.
I run a function that does some stuff inside a while True
.
Problem:
Sometimes, due to a lack of conectivity with the phone, or whatever other problems, the program just does not keep running the right way.
There are a lot of factors that might cause the whole thing to lose the right flow. I am analyzing them all and fixing them as best as I can.
Question:
I came up with the idea that maybe if I restart the whole thing every hour (or every whatever-thousands iterations) it would become more solid. As it will refind the flow no matter what happens, if I did not catch the bug yet.
Is it possible to restart the whole thing, without losing the browser session? Whatsapp web requires a QR scan, but it allows a "keep session alive in further connections" (which I do not really know how it works... if cookies or something else.)
Note: I know that a python script can be rebooted, but the bigger problem here is to reuse the browser session. Of course I am doing my research. None of what I read so far made me come with a solid solution, and that is why I ask to all the super cool brains out there.
回答1:
Whatsapp stores session in localStorage
of the browser.
You can extract the localStorage and save to a file on closing of a session.
Upon instantiating a session check if this file exists, then parse the file and update localStorage with saved values before opening a URL.
来源:https://stackoverflow.com/questions/45413194/python-and-selenium-reboot-program-and-reuse-same-browser-session