保存/加载登录Cookie Selenium

编程入门 行业动态 更新时间:2024-10-23 20:16:39
本文介绍了保存/加载登录Cookie Selenium的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想第一次保存登录Cookie,然后下次加载 这样我就不必每次都执行登录.

I want to save a login cookie in first time , then load it next times so the i won't have to perform a login each time.

有什么想法吗?

public void mControlClick() { var options = new ChromeOptions(); var chromeDriver = new ChromeDriver(options); chromeDriver.Navigate().GoToUrl("website") }

推荐答案

我遇到了类似的问题.看着开发人员窗口,我可以看到登录后发送了Cookie,但是通过javascript或其他内容进行的页面正在重定向,然后将控制权还给了程序.因此,我无法获取该cookie并将其保存.

I had a similar issue. Watching with the developer window, I could see that after login a cookie was being sent but then the page via javascript or something else was redirecting before returning control to the program. So, I was unable to get that cookie and save it off.

经过更多研究,我意识到该程序每次都从一个干净的会话开始(此答案很有帮助)因此持久性cookie根本不是持久性的.经过了进一步的研究,但是(通过碎片)为硒提供了解决方案,从而解决了我的问题.我实际上在使用python,但是我确定C#的选项仍然遵循

After more research I realised that the program was starting with a clean session each time (this answer helped a lot) so the persistent cookies weren't persistent at all. It took further research, but giving selenium (via splinter) a profile to work with resolved my issue. I am actually using python, but I'm sure the options still follow for C#

chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("user-data-dir=" + tdir + "/chrome-session") chrome_options.add_argument("--profile-directory=Default") with Browser('chrome', headless=True, options=chrome_options) as browser:

更多推荐

保存/加载登录Cookie Selenium

本文发布于:2023-10-11 23:23:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483130.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   Cookie   Selenium

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!