簡體   English   中英

保存鉻餅干硒

[英]Saving chrome cookies Selenium

我正在尋找一種方法來保存chrome會話cookie,即使我的程序關閉后,它們也可以持久保存。 我假設寫入文件將是執行此操作的好方法,但是我對如何完成此操作感到困惑。 我的最終目標是保存登錄cookie,以便用戶不必每次都執行登錄。 這是一些代碼:

Dim driver = New Chrome.ChromeDriver()
driver.Navigate.GoToUrl("URL")
'click stuff and login here
Dim _cookies = driver.Manage().Cookies.AllCookies
'write cookies to file or save somehow

您需要在所需的用戶個人資料下運行Chrome。 默認情況下,Selenium Web驅動程序將創建一個臨時配置文件。 如果您為其提供用戶個人資料,則該個人資料將保留下來,並且如果未將Chrome設置為刪除Cookie,則會創建通常會為用戶創建Cookie的所有登錄信息。

有關詳細信息,請參見Selenium chromedriver網站

Use custom profile (also called user data directory)
By default, ChromeDriver will create a new temporary profile for each session. At times you may want to set special preferences or just use a custom profile altogether. If the former, you can use the 'chrome.prefs' capability (described later below) to specify preferences that will be applied after Chrome starts. If the latter, you can use the user-data-dir Chrome command-line switch to tell Chrome which profile to use:

ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");

You can create your own custom profile by just running Chrome (on the command-line or through ChromeDriver) with the user-data-dir switch set to some new directory. If the path doesn't exist, Chrome will create a new profile in the specified location. You can then modify the profile settings as desired, and ChromeDriver can use the profile in the future. Open chrome://version in the browser to see what profile Chrome is using.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM