1

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.

Álvaro N. Franz
  • 1,188
  • 3
  • 17
  • 39
  • the "other problems" will likely cause errors to occur in your python script. You should be catching them and dealing with them. – asongtoruin Jul 31 '17 at 10:21
  • @asongtoruin I am doing so. Still though, there are things that I did not catch yet or which are completely out of my control. And this would be a great add-on mode. Not to ignore everything and just reboot. But to fix as much as possible and also reboot for double trouble fixer. – Álvaro N. Franz Jul 31 '17 at 10:26

1 Answers1

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.

Oluwafemi Sule
  • 36,144
  • 1
  • 56
  • 81
  • I did so but still it won't grab the session. I posted new question because it now is a new question: https://stackoverflow.com/questions/45415178/python-and-selenium-reuse-a-whatsapp-web-session - Thank you. – Álvaro N. Franz Jul 31 '17 at 11:51