2016-08-27 2 views
0

내 프로그램을 종료 한 후에도 크롬 세션 쿠키를 저장하는 방법을 찾고 있습니다. 파일 쓰기는이 작업을 수행하는 좋은 방법이 될 것이라고 생각하지만이 작업을 수행하는 방법에 관해서는 손해보고 있습니다. 나의 최종 목표는 사용자가 매번 로그인을 수행 할 필요가 없도록 로그인 쿠키를 저장하는 것입니다. 다음은 약간의 코드입니다.크롬 쿠키 저장 Selenium

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 

답변

4

필수 사용자 프로필로 Chrome을 실행해야합니다. 기본적으로 Selenium 웹 드라이버는 임시 프로필을 생성합니다. 사용자 프로필에 프로필을 제공하면 프로필이 유지되고 Chrome에서 쿠키를 삭제하도록 설정되지 않으면 일반적으로 사용자에 대한 쿠키를 만드는 로그인 등이 생성됩니다.

은 자세한 내용은 Selenium chromedriver site를 참조하십시오

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. 
+1

그 감사를 돌봐 그. 부끄러운 거기에 너무 많은 추가 데이터가 있지만이 확실히 작동합니다. –