【问题标题】:Python and Selenium - Reuse a whatsapp web sessionPython 和 Selenium - 重用 whatsapp 网络会话
【发布时间】:2017-07-31 11:50:18
【问题描述】:

我想在 Chromedriver 上通过 Python 3 和 Selenium 重用 whatsapp 网络会话。

为此,我需要获取现有会话的本地存储并将其设置为新的浏览器实例,然后再次打开 whatsapp 网络。

我在登录会话中这样做:

cacho="";
for (var i = 0; i < localStorage.length; i++){
cacho+="localStorage.setItem('"+localStorage.key(i)+"', '"+localStorage.getItem(localStorage.key(i))+"');"
}
alert(cacho)

使用 driver.execute_script(),我得到了工作的本地存储数据。

我复制整个内容(几行 javascript),然后在打开一个新的浏览器实例时复制:

driver.execute_script(the_whole_thing)
driver.get(url)

但是会话没有激活。

我在这里错过了什么?

【问题讨论】:

标签: python selenium session


【解决方案1】:

这是您可以通过存储 cookie 重用 whatsapp 网络会话的方法。

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-20
    • 1970-01-01
    • 2020-02-16
    • 1970-01-01
    • 2010-12-22
    • 2022-08-23
    • 1970-01-01
    • 2018-09-24
    相关资源
    最近更新 更多