Authorization in web.whatsapp using python requests

Viewed 443

I wrote a script in selenium that loads the web.whatsapp page and finds the QR code for authorization in the source code. The script sends a QR code to my telegram and thus I can authorize someone's account on my home computer remotely.

from time import sleep
from qrcode import make
from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://web.whatsapp.com/")
sleep(3) #wait for load the QR
value =  driver.find_element_by_css_selector("div[data-ref]").get_attribute("data-ref") #find for a value encoded in QR
print(value)
make(value).save("qr.png") #make my qr using the previous value
send_to_tg("qr.png") # send qr 
sleep(17) # wait for auth
try:
    side = driver.find_element_by_id("side") # if "side" exist, authorization was successful
    cookies = driver.get_cookies()
    print(cookies)
except Exception:
    print("Noup !")

It works, but i can't keep the browser page open all the time, so i tried to save cookies, but selenium does not detect any cookies at all, if you call "driver.get_cookies()" after authorization it returns an empty array "[]".

I check source code the web.whatsapp page after auth and found cookies there, see the picture.

cookie picture

So I have one question that hides in itself two ways to solve the problem, the first is: how can I save cookies web.whatsapp and then continue to use the authorized account in other browsers ?

And the second: can i start a session in the requests, so that after authorization, I can also save cookies and use them in another browser?

0 Answers
Related