我的期望是验证后会自动将某些内容添加到 cookeies 数组中,但事实并非如此。
driver = webdriver.Chrome(chromedriver)
whatsapp_url = "https://web.whatsapp.com"
driver.get(whatsapp_url)
print(driver.get_cookies())
time.sleep(30) # We are doing the manual QR code verification here
print(driver.get_cookies())
driver.get_cookies()
之前和之后也是空的
试试这个:
options = webdriver.ChromeOptions();
options.add_argument('--user-data-dir=./User_Data')
driver = webdriver.Chrome(chrome_options=options)
driver.get('https://web.whatsapp.com/')
您需要首次登录。 当您必须存储会话时,它将始终有效。无需导入/导出饼干。
我无法评论Abhi Bhalgami的回答,但我需要根据另一篇文章进行一些更改:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chromepath = r'E:chromedriverchromedriver.exe'
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\Users\user\AppData\Local\Google\Chrome\User Data")
driver = webdriver.Chrome(executable_path=chromepath, chrome_options=options)
从Chrome浏览器本地存储中提取并保存WhatsApp会话,然后在另一台设备上使用它
https://pt.stackoverflow.com/questions/241604/salva-o-estado-ou-os-cookies-do-navegador-utilizando-o-selenium
这对我来说很好!我
import os
from selenium import webdriver
dir_path = os.getcwd()
profile = os.path.join(dir_path, "profile", "wpp")
options = webdriver.ChromeOptions()
options.add_argument(
r"user-data-dir={}".format(profile))
browser = webdriver.Chrome("./chromedriver.exe", chrome_options=options)
browser.get("https://web.whatsapp.com")
不确定,但您可以使用泡菜保存您当前的 cookie,例如:
import pickle
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://www.google.com")
pickle.dump( driver.get_cookies() , open("cookies.pkl","wb"))
之后,使用以下代码重新添加它们:
import pickle
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://www.google.com")
cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
driver.add_cookie(cookie)
Web Whatsapp将会话存储在IndexedDB中,并将这些值同步到本地存储。
以下是你可以尝试的工作代码:tithiwa/session.py通过使用这个javascript代码