[英]I'm unable to load cookies into a headless chrome session + selenium (MacOS)
I'm trying to load cookies from a previous session into a new headless chrome session using selenium, if i try to load them using the same method i do with chrome but not in headless mode and taking a screen shot, it doesn't work because instead of being logged into the site takes me to the login screen. I'm trying to load cookies from a previous session into a new headless chrome session using selenium, if i try to load them using the same method i do with chrome but not in headless mode and taking a screen shot, it doesn't work因为我没有登录到该站点,而是将我带到了登录屏幕。
I've already tried passing via Options() a cookies folder or saving them with pickle and uploading once to the site like that:我已经尝试通过 Options() 传递一个 cookies 文件夹或用泡菜保存它们并像这样上传一次到网站:
options = Options()
options.headless = True
driver = webdriver.Chrome(options=options)
driver.get('site')
cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
driver.add_cookie(cookie)
driver.refresh()
but neither one worked.但没有一个工作。
I have already searched if anyone has ever encountered my problem, but all the question is about loading cookies with selenium in a normal chrome session.我已经搜索过是否有人遇到过我的问题,但所有问题都是关于在普通镀铬 session 中使用 selenium 加载 cookies。
Thanks to all reply.感谢大家的回复。
You have to be on another site, load cookies and then redirect to the desired page.您必须在另一个站点上,加载 cookies 然后重定向到所需的页面。
options = Options()
options.headless = True
driver = webdriver.Chrome(options=options)
driver.get('other_site')
cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
driver.add_cookie(cookie)
driver.get('site')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.