Selenium-在计算机之间共享浏览器会话(cookie,本地存储)

Bar*_*art 5 python cookies selenium google-chrome selenium-chromedriver

我需要在两台计算机之间转移我的Selenium会话。

要通过Selenium导出和导入cookie,您必须分别访问每个网站,然后才能设置其cookie,我想避免这种情况。我也想复制本地存储。

到目前为止,这是我尝试过的方法:

1-启动新的Selenium会话:

driver = webdriver.Chrome()
Run Code Online (Sandbox Code Playgroud)

2-在%temp%中找到其临时Chrome用户配置文件,并将其复制到我的应用程序的文件夹中

3-使用此用户配置文件启动新驱动程序:

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("user-data-dir=C:\\profiles\\temp_profile")
driver = webdriver.Chrome(chrome_options=chrome_options)
Run Code Online (Sandbox Code Playgroud)

上面的作品-本地存储和cookie仍在我的本地PC上,但是,当我将此用户配置文件复制到另一台PC并启动它时,本地存储仍然存在,但cookie消失了。

我还使用常规的chrome配置文件尝试了相同的操作,并尝试直接在Chrome中而不是在Selenium中启动用户配置文件,并且cookie仍然消失了。

Mos*_*sho 3

由于 cookie 存储在 Chrome 的 SQLite 文件中,并且它们是加密的,因此您并不真正知道(或想深入了解..)为什么它不起作用。这可能与信息安全有关。

所以我的建议是使用 WebDriver 的功能保存它们并将它们加载到内存中。看这里